Alex Rivera | Logout

How can I unserialize session data to an arbitrary variable in PHP?

Asked 2009-02-10T01:21:16.360
15

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
Report

1 Answer

7

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.

answered 2009-02-10T01:28:21.773

Your Answer