|
Posted by bmaster on 03/12/06 17:59
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;
?>
Navigation:
[Reply to this message]
|