please help with sessions problem

From: Date: Sun, 26 Nov 2000 20:59:59 +0000
Subject: please help with sessions problem
Groups: php.general 
Request: Send a blank email to php-general+get-27280@lists.php.net to get a copy of this message
Hi Everyone =) I posted on Friday and haven't seen any response, so I figured I'd try again. I setup PHP4 to store session variables using the handler from here: http://gateway.digitaria.com/~chris/php/mysql_session_handler/ I can start sessions, register, retrieve, and unregister variables. I was able to quickly setup a system where people can log into the site, etc. I also setup a neat little extra. By adding two additional fields to the sessions database (username, url), and adding these fields to the function that writes the sessions (listed below), I'm able to tell who's logged in and which page they are on. Pretty cool =) I've run into one problem tho :( If you don't do anything on your browser for a while and go back, things are broken; Session variables and the ability to store them is lost. Did I screw something up? Any idea of what the solution would be? Thanks in advance for any help you could provide! =) -Ed ---------- modified sess_write -------------------- function sess_write($key, $val) {
        // Added handling for Username and REQUEST_URI to make user administration easier.  Ed, 11-22-2000
        global $SESS_DBH, $SESS_LIFE, $user, $REQUEST_URI;
        // Added for tracking users through the site - Ed, 11-22-2000
        if (empty($user["Username"]))
                $Username = "nobody";
        else
                $Username = $user["Username"];
        $expiry = time() + $SESS_LIFE;
        $value = addslashes($val);
        // SQL statement modified to add $Username and $REQUEST_URI. Ed, 11-22-2000
        $qry = "INSERT INTO sessions VALUES ('$key', $expiry, '$value', '$Username', '$REQUEST_URI')";
        $qid = mysql_query($qry, $SESS_DBH);
        // SQL statement modified to add $Username and $REQUEST_URI. Ed, 11-22-2000
        if (! $qid) {
                $qry = "UPDATE sessions SET expiry = $expiry, value = '$value', username = '$Username', url = '$REQUEST_URI' WHERE sesskey = '$key' AND expiry > " . time();
                $qid = mysql_query($qry, $SESS_DBH);
        }
        return $qid;
}

« previous php.general (#27280) next »