PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
After looking around for what seemed like forever, I can't seem to get this correct. I initialize an object on page 1 and do everything I need to do and then when I save it in a session variable and try to use that very session varible on the next page, it will not access the class anymore. If I have it echo the variable it says "Object" so I know it's passing properly.
I haven't actually done this, but I think this is what you need to do. I may be way off so test this or get someone to confirm it.
You need to serialise the object and then unserialise it on the other side. In other words, take the object as it is, convert it to a string, store the string in the session. And on the next page, take the string, and convert it back to the object.
Thanks. I just unserialized it and now it's working.
As for the error in my code example, just an error in copying it into here, not actually an error in my code.
One thing I don't understand is that I thought session_register() was supposed to serialize and unserialize for you... Now in file 1 I just session_register('user'); and then on file 2 in order for it to work i have to use $user = unserialize($_SESSION['user']); . Oh well, it's working now. Thanks.
Hi,
session_register() is deprecated, just use session_start() and the $_SESSION array.
If you store objects in the session, be sure to include the *class* before session_start(), otherwise your *object* is a "zombie" without being linked to the class.