views:

943

answers:

2

I want to unserialize a session_encode()'d string of session data to my own array (i.e. not to $_SESSION.)

There doesn't appear to be an in-built function that handles this. There's session_decode() but it writes directly to the $_SESSION super-global. There's unserialize() but it returns false on session_encode()'d strings as they're a slightly different format.

What's the best way to do this?

EDIT: This is the code I went with: http://us.php.net/manual/en/function.session-decode.php#79244

+2  A: 

Check out the comments in the PHP manual's session_decode page. It has a bunch of user functions to handle decoding a session_encode string manually. As far as I know, that's the only way to go.

Paolo Bergantino
I used the first answer on that manual page. I've edited my post to include a direct link to that answer.
A: 

Why don't you just do something like this?

$myVariable = serialize($_SESSION);
$sessionCopy = unserialize($myVariable);

Good luck!

Ian P
Because sessions are serialized in a different format to serialize/unserialize()