PHP 4 SESSION + MYSQL + MOD_REWRITE

From: Date: Wed, 13 Dec 2000 17:27:15 +0000
Subject: PHP 4 SESSION + MYSQL + MOD_REWRITE
Groups: php.general 
Request: Send a blank email to php-general+get-30112@lists.php.net to get a copy of this message
Ok, I've been breaking my head on this one for a while now. This is my first time working with sessions. I am following one of the examples in the "Web Application Development with PHP 4" book. I am storing sessions in a mysql db then passing the session from page to page doing a URL rewrite with mod_rewrite. This part of it is working correnctly. But I am confused as to how I retrive the session_id or any of the other session variables. The entries in the sessions table look like this: COLUMN 1: id -------------------------- 16d77df44f8b0ed2627a9f27c3a7bc8c COLUMN 1: data -------------------------- session_id|s:12:"976724840763";counter|i:1;username|s:5:"joe";password|s:7:"towtruck"; COLUMN 3: timestamp -------------------------- 20001213082720 This is the function that starts the session and sends header for the url rewrite: function session_start_from_rewrite() { global $HTTP_HOST, $REQUEST_URI; ereg("/([0-9a-z]{32})", $REQUEST_URI, $regs); $session_id = $regs[1]; if(!isset($session_id) || empty($session_id)) { srand((double)microtime()*1000000); $session_id = md5(uniqid(rand())); $destination = "http://$HTTP_HOST/$session_id$REQUEST_URI"; header("Location: $destination"); } session_id($session_id); session_start(); } After authenticating use, this code saves session vars to db and calls the session_start_from_rewrite() function to start the session: process_login.php -------------------------- .. if ($exist_user) { $counter = 0; session_set_save_handler("sess_mysql_open", "", "sess_mysql_read", "sess_mysql_write", "sess_mysql_destroy", "sess_mysql_gc"); session_start_from_rewrite(); session_register("session_id"); session_register("counter"); session_register("username"); session_register("password"); $counter++; } else { .. } To test sessions I created a seperate temp page with the following: .. session_start_from_rewrite(); $echo "$username"; $echo "$password"; $echo "$session_id"; . But I get blank. So my questions are: 1. Do I need to store the session id with the rest of my variables in the data column as I am doing now? 2. When I verify wether session id is set, do I check for $session_id or $PHPSESSID? 3. Why can't I retrieve session variables on my temp page, what am I missing? Shine some light on me with this one! Thanks in advance.

« previous php.general (#30112) next »