Re: manually unserializing session data

From: Date: Sat, 14 Jun 2003 22:40:09 +0000
Subject: Re: manually unserializing session data
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-151526@lists.php.net to get a copy of this message
http://us3.php.net/manual/en/function.session-decode.php Andrew Warner wrote:
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
-- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.

« previous php.general (#151526) next »