manually unserializing session data

From: Date: Sat, 14 Jun 2003 21:23:13 +0000
Subject: manually unserializing session data
Groups: php.general 
Request: Send a blank email to php-general+get-151511@lists.php.net to get a copy of this message
How do you manually unserialize session data? Using unserialize() on session data from a sessions table is not working for me. I have modified the gc function of my MySQL session handler to save data from expired session records to another table, 'sessions_saved'. I can get the session data out and into the sessions_saved table okay, but i can't restore some of the saved session variables i need for field values in the sessions_saved table. In the code below, $sess_data['pid'] is always empty even though I can see it and its value in the serialized session data. The $pid value has already been set to a session value using: session_start(); $_SESSION['pid'] = $pid function mysql_sess_gc ($sess_maxlife) { (code here to query session table for expired sessions) // loop thru expired sessions and save to 'sessions_saved' table: while (list($sess_id,$data) = mysql_fetch_array($r)) { $sess_data = unserialize($data); $pid = $sess_data['pid']; $sid = $sess_data['sid']; //store sessions in saved_sessions table $query = "INSERT INTO sessions_saved (id,pid,sid,data) VALUES ('$sess_id',$pid,$sid,$data)"; $result = mysql_query ($query, $mysql_sess_conn_id); } (...now delete expired sessions from sessions table) } andrew

« previous php.general (#151511) next »