You are here: storing object in session « PHP Programming Language « IT news, forums, messages
storing object in session

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация