note 22358 added to function.session-decode

From: Date: Fri, 14 Jun 2002 18:37:31 +0000
Subject: note 22358 added to function.session-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-31868@lists.php.net to get a copy of this message
I wrote a script to show me a list of the current sessions, and various items I keep in every session (IP address, Number of visits, time the session was created, etc). I needed a way to access the variables of a session I read from disk without altering the current session. Since session_decode() wrote them directly to globals, this would not do. You also can't call unserialize directly on the string since it consists of multiple variables, but they are not in array format. I came up with this: function sess_string_to_array($sd) { $sess_array = Array(); $vars = explode(';', $sd); for ($i=0; $i < sizeof($vars); $i++) { $parts = explode('|', $vars[$i]); $key = $parts[0]; $val = unserialize($parts[1].";"); $sess_array[$key] = $val; } return $sess_array; } Hope that helps someone out =) -- http://www.php.net/manual/en/function.session-decode.php http://master.php.net/manage/user-notes.php?action=edit+22358 http://master.php.net/manage/user-notes.php?action=delete+22358 http://master.php.net/manage/user-notes.php?action=reject+22358

« previous php.notes (#31868) next »