SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2003
    Location
    Melbourne, Australia
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php 5.1.4 bug or code error

    hi all

    i am having this issue with my login script that is really annoying
    in php 5.1.2 it works fine (using pdo, mysql 4.1.16)

    in php 5.1.4, the script logs the user in, but dies, so the user must hit refresh or type in the url to access the admin section

    basically i have a login class that is loaded on every page
    if the user is already logged in, it goes through the confirmLogin method (which works fine in both versions (db is not accessed))

    but when the user logs in, it goes through the validateLogin method
    which authenticates the user based on username/password using prepared statements going through the db (this is where it dies in php 5.1.4)

    unfortunately i don't have the code on me right now, but basically
    PHP Code:
    function validateLogin($username$pw$referer) {
    //prepare query
    try {
    $sql "select username from users where username = ?";
    //execute query --> works but script dies here, at the prepare line
    // i've put exit lines all through the code, so it's not a redirect issue or anything like that, definitely stops at the following line
    $stmt $this->dbh->prepare($sql);
    $stmt->bindParam(1$usernamePDO::PARAM_STR);
    //get result and do some another query to get all details and redirect to the referer page
    //also works, but because the script has died, does not send the user to the page
    }
    }

    $l->validateLogin($username$password$referer); 
    just assume everything else is setup, eg. db conn, etc.

    could this be an apache issue (apache 2 on fc4)?
    i've checked the error log, but there is nothing there, all i get is this cannot find server error in the browser

    it seems strange that it works on php 5.1.2, but not 5.1.4

    it is hard to post the whole code because it spans about three or four scripts

    i will try to replicate the code all in one page, but just wanted to see if anyone had any ideas based on what i have mentioned above

    thanks
    dave

  2. #2
    SitePoint Enthusiast didimo's Avatar
    Join Date
    Jan 2006
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    interesting i have a similar authentication class and im not having any problems with pdo,

    infact pdo is growing on me now


    i update my development machine (win xp to 5.1.4 from 5.1.2) with no problems on my classes which use PDO prepared statements

    ill recompile php to 5.1.4 on my main server (php5.1.2 currently on suse 64bit) later see if i encounter any problems

  3. #3
    Codehead. hamidof's Avatar
    Join Date
    Dec 2005
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Intresting, I have the save problem sometimes with 5.0.4, but It seems like mine is just happening with IE, not FF or Opera, try those browsers, and if it's fine then we found a big bug in IE!

  4. #4
    SitePoint Enthusiast didimo's Avatar
    Join Date
    Jan 2006
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i bind my parameters a small bit differently but im not having problems

    (if u having trouble with IE what does it have to do with mysql?)

    PHP Code:
        /**
         * starts a session for a visitor
         */
        
    private function startUserSession($user_id$user_hash){
            
            
            
    $session_key        =    $this->createKey();
            
    $this->session_hash    =    md5($session_key);
            
            
    Framework::loadClass('User');
            
    $User    =    new User($this->DB);
            
    $User->retrieveUserByUserIdAndHash($user_id$user_hash);
            
            
            
            
    $this->session['user_id']    =    $User->get('user_id');
            
    $this->session['user_name']    =    $User->get('username');
            
    $this->session['user_level']=    $User->get('level');
            
    $this->session['timestamp']    =    time();
            
    $this->session['location']    =    strip_tags($_SERVER['REQUEST_URI']);
            
    $this->session['ip']        =    Framework::ip2longFramework::getIP() );
            
    $this->session['timestamp']    =    time();
            
            
            try {
                
                
    $STMT $this->DB->prepare(
                
    "INSERT INTO sessions (    session_key, 
                                        user_id,  
                                        user_name, 
                                        user_level, 
                                        location, 
                                        ip, 
                                        timestamp )
                                        VALUES (:session_key, 
                                                :user_id,  
                                                :user_name, 
                                                :user_level, 
                                                :location, 
                                                :ip, 
                                                :timestamp )" 
    );
                
                
    $STMT->bindParam":session_key",     $session_key,                     PDO::PARAM_STR,    );
                
    $STMT->bindParam":user_id",         $this->session['user_id'],        PDO::PARAM_INT );
                
    $STMT->bindParam":user_name",     $this->session['user_name'],    PDO::PARAM_STR );
                
    $STMT->bindParam":user_level",     $this->session['user_level'],    PDO::PARAM_INT );
                
    $STMT->bindParam":location",         $this->session['location'],        PDO::PARAM_STR );
                
    $STMT->bindParam":ip",             $this->session['ip'],            PDO::PARAM_INT );
                
    $STMT->bindParam":timestamp",        $this->session['timestamp'],    PDO::PARAM_INT );
                
                
                
    $STMT->execute();
                
                
    $this->session_id    =    $this->DB->lastInsertId();
            } 
            catch (
    PDOException $e) {
               
                
    Framework::handleException($e);
            }
            
            
    $this->createUserCookieSession$this->session_id$this->session_hash$this->session['user_id'], $user_hash );
        } 

  5. #5
    Codehead. hamidof's Avatar
    Join Date
    Dec 2005
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if u having trouble with IE what does it have to do with mysql?
    I don't know!

  6. #6
    is_empty(2); foofoonet's Avatar
    Join Date
    Mar 2006
    Posts
    1,000
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you leave your old PDO class .dlls lying around?

    Did you change version of Mysql?

    Are you sure you correctly installed the PDO driver for mysql? and the prepare statement drivers?

    Sorry cant help more, just installed 5.1.4 on win but didnt config it to use PDO yet incase it clashed with a utility PDO4PHP4 class I was using on that machine. Still, on the install process I noticed it might be tricky to set up.

    Will it work with a straight ->query(); ?

  7. #7
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have a try without a catch ?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •