Serializing objects and storing them is sessions

I'm having a problem unserializing objects that are passed from page to page with sessions. Registered globals is disabled so I am using the $_SESSION array to store session variable and am not using session_register(). Here's what I'm doing.

On first page:
PHP Code: require_once('MyClass.php');

Second page:
PHP Code: require_once('MyClass.php');

When I var_dump() $_SESSION it appears to be a string representation of the object. However, when I try to unserialize() it and store it in $auth the value is bool(false) and not an object. Can anyone tell me what I am doing wrong , Quote: Have you tried to actually utilize the object and its methods in the second script

My apologies, since I was not clear enough in previous posts. I have indeed tried to use the actual class after unserializing it. I get an error much like this one.

Quote: Fatal error: Call to a member function on a non-object in /path/to/php/script/test.php on line 12

As you said, var_dump does see the session as a string (and what appears to me to be a proper serialized object string) after session_start() is called. Since it is still a string I try to unserialize() it. If I var_dump() that variable I get bool(false) as the contents meaning, that for some reason that is still a mystery to me, the session variable is not properly being unserialized.
Posted On: Wednesday 24th of October 2012 12:32:29 AM Total Views:  229
View Complete with Replies