|
Posted by Kimmo Laine on 09/07/06 08:36
"nephish" <nephish@gmail.com> wrote in message
news:1157550802.659286.20280@b28g2000cwb.googlegroups.com...
> OK, i have a new question now.
> can i set a class object in a session variable ?
>
> like this:
>
> class Person
> {
> function Person($name)
> {
> $this->name = $name;
> }
> }
>
> $frank = new Person;
> $_SESSION['name'] = $frank;
>
> or is this just too much ?
> }
Not just like that, you must first convert the object to a storeable format,
it's called serializing. There is a function called serialize() and it's
compliment function unserialize(). When you store the object to session, you
serialize it first. then when you need to revert it back from the session,
you unserialize it. And also, the class definition must be available on each
page where the object is accessed. If it is missing, the object can't be
unserialized.
on page1.php:
$_SESSION['name'] = serialize($frank);
on page2.php:
$frank = unserialize($_SESSION['name']);
--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti pδivittyvδ nettisarjis
spam@outolempi.net || Gedoon-S @ IRCnet || rot13(xvzzb@bhgbyrzcv.arg)
Navigation:
[Reply to this message]
|