note 55307 added to function.session-decode
| From: | brett at brettbrewer dot com | Date: | Fri, 29 Jul 2005 18:25:35 +0000 |
| Subject: | note 55307 added to function.session-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92737@lists.php.net to get a copy of this message | ||
I have made a minor change to fabrizio's (et all) version of the unserializesession function
because it was choking on underscores in my variable names. Here is the correct version which
should account for ALL possible PHP variable names:
function unserializesession($data) {
$vars=preg_split(
'/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\|/',
$data,-1,PREG_SPLIT_NO_EMPTY |
PREG_SPLIT_DELIM_CAPTURE
);
for($i=0; $vars[$i]; $i++) {
$result[$vars[$i++]]=unserialize($vars[$i]);
}
return $result;
}
Please note that I had to split the preg_split function call above into 4 lines due to the
limitations of this forum. This version changes the regex used to find variable names so that it
complies with the specs for variable names as specified in the PHP manual at http://us3.php.net/manual/en/language.variables.php.
I just took the regex directly from the PHP manual pages where they give the regex equivalent for a
valid variable name as:
[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
Anyway, this seems to work great for me now, even on gigantic strings of encoded session data.
----
Submitter IP: 12.160.245.96
----
Manual Page -- http://www.php.net/manual/en/function.session-decode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55307
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55307&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55307&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55307&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55307&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55307&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55307&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55307&report=yes
Search -- http://master.php.net/manage/user-notes.php