storing object in session



Hi there,

I'm trying to figure out how to store an object in session. To try
this, I have apache2 and php5 running on my windows machine. I used the
2 files below. First i run test.php, which creates the object, puts
some data in it, and stores it in the session. test2.php retrieves the
object from the session and prints the data. Works fine on my windows
machine. However, when I upload these 2 files to my hosting provider,
then it does not work anymore. I get no errors, but the object seems to
be empty. The provider is running php4.3 ... Can someone help me find a
way to fix this? Thanks!!


-------- test.php -----------------------------------------------------
<?php
class claUser{
var $firstname;
var $lastname;
}

session_start(); // Start Session

$user = new claUser;

$user->firstname = "abc";
$user->lastname = "def";

$_SESSION['user'] = serialize($user);


?>

-------- test2.php
-----------------------------------------------------
<?php
class claUser{
var $firstname;
var $lastname;
}

session_start(); // Start Session


$user = new claUser;

if (isset($_SESSION['user']))
{
$user = unserialize($_SESSION['user']);
}

print $user->firstname;


?>

.



Relevant Pages

  • Re: HTA error in Windows Vista
    ... this file can be included in master HTA frames only!!! ... var strcomputer = "." ... it will just start another HTA subapp instead of calling ... it will at least fix the session ID ...
    (microsoft.public.inetsdk.programming.scripting.vbscript)
  • Re: Howto: ssh X11 display to Win2k
    ... > graphical display over to my Win2K box. ... just fire up the vncserver process on your linux machine, ... start the vncviewer process on your windows machine, ... manager in a VNC session, ...
    (linux.redhat.misc)
  • Re: Why Doesnt This Work?
    ... code that is supposed to allow for me to persist session state. ... var Max = 1000; ... I set the session timeout value to "1" in the web.config file. ... a "Server Error in '/' Application - Object reference no set to an ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: [PHP] accessing one objects attribute from another
    ... am running into an odd thing that I can't figure out what a ... var $thisVar; ... There are a number of variables and methods that are common throughout ... stored in the object that is hanging around in the session. ...
    (php.general)
  • Re: [PHP] accessing one objects attribute from another
    ... am running into an odd thing that I can't figure out what a ... var $thisVar; ... There are a number of variables and methods that are common throughout ... stored in the object that is hanging around in the session. ...
    (php.general)