note 46112 added to function.session-decode
| From: | luc at lucje dot removethisforspamplease dot nl | Date: | Wed, 29 Sep 2004 19:37:24 +0000 |
| Subject: | note 46112 added to function.session-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-77582@lists.php.net to get a copy of this message | ||
I also wanted to read stores PHP sessions.
Here's my code:
function unserializesession($data) {
$vars=preg_split('/([a-z,A-Z]+)\|/',$data,-1,PREG_SPLIT_NO_EMPTY |
PREG_SPLIT_DELIM_CAPTURE);
for($i=0; $vars[$i]; $i++) {
$result[$vars[$i++]]=unserialize($vars[$i]);
}
return $result;
}
// this is just for the example
$session='/tmp/sess_'.$PHPSESSID;
// Why isn't there a sfile() function that returns a file as a string?
$h=fopen($session,'r');
$data=fread($h,filesize($h));
fclose($h);
$data=unserializesession($data);
Voila. It does the trick for me :-)
----
Manual Page -- http://www.php.net/manual/en/function.session-decode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46112
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46112&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46112&report=yes
Search -- http://master.php.net/manage/user-notes.php