Re: Handling objects as session vars

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'd say not to both with serialize. Your just adding extra work when there is no need to.

It is possible to pass Objects across Sessions. I do it on my E-Commerce site by using a Shopping Cart object (it even says so on php.net!). Are you sure there is nothing wrong in the Class (that it is setting the data that you want correctly)? Try...

if (isset($_SESSION['session_object'])) {
   // do something
}

.... to see if the session is actually.

(I will check my code later when I get home to see if this is correct)

Tryst

-----Original Message-----
From: David Collard <meizawotmeiz@xxxxxxxxx>
To: Marcos R. Cardoso <mcardoso@xxxxxxx>
Cc: php-windows@xxxxxxxxxxxxx
Sent: Tue, 11 Oct 2005 15:57:50 +0100
Subject: Re:  Handling objects as session vars

 Marcos R. Cardoso wrote:

i'd try using serialize() to turn the object into a string which can then be put in the session, and then unserialize() when you want it back out again

sessions work by using cookies, and cookies can't take php objects

;)

> I'm trying to use an object as a session var so I could handle its > properties and methods as long as the session is still on. But when I > use a second PHP script the values inside this object are lost. I have
a script like this.
>
> <?
> include("class/object_def.php");
> session_start();
> $new_object = new TNewClass($cod,$password);
> if ($new_object->getCod() == 0) {
> echo $new_object->getMsgError();
> } else {
> $_SESSION['session_object'] = $new_object;
> ?>
> <script language="JavaScript">
> location.replace("new_script.php");
> </script>
> <?
> }
> ?>
>
> then in the script "new_script.php" I have the following instructions:
>
> <?
> include("class/object_def.php");
> session_start();
> if ($_SESSION['session_object'] == "") {
> echo "there is no session open<br>";
> exit;
> }
> echo $_SESSION['session_object']->getCod()."<br>";
> echo $_SESSION['session_object']->getName()."<br>";
> ?>
>
> The result from the script new_script.php always return empty where > the methods should return something. I've already read the > documentation at www.php.net, tried what it's shown there and checked > some other sites as well, bu I haven't found a solution yet.
>
> Environment:
>
> Windows 2003 Server
> Apache 2.0.54
> PHP 4.4.0
> Sun Chili!Soft ASP 3.6.2
> MySQL 4.0.20a
> Oracle 9i (through a Oracle 8i NetClient)
>
>
> TIA,
> Marcos R. Cardoso
> Blumenau
> Brazil
>

-- PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux