Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-03-2009
Member
 
Join Date: Nov 2008
Posts: 1,221
Variables of sessions and classes

I explain my problem:

In a method call, when a user login, it create an object that I stored in a session variable in the future, like this:

$user = new User($id, $name, $email, $password, $level, $lang);
$_SESSION ['User'] = $user;

Then, in another page, I get my item in a variable:
$user = $_SESSION ['user'];

And when I do:
echo $user->id;

I get the following message:
Notice: main () [function.main]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "User" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition

I do not understand why it does not. Someone has an idea?
Reply With Quote
  #2  
Old 26-03-2009
Member
 
Join Date: May 2008
Posts: 685
Re: Variables of sessions and classes

Try any (code not tested):

PHP Code:
$_SESSION['User'] = serialize($user); 
and
PHP Code:
$user unserialize($_SESSION['user']); 
Reply With Quote
  #3  
Old 26-03-2009
Member
 
Join Date: Nov 2008
Posts: 1,221
Re: Variables of sessions and classes

It works, thank you very much! You could tell me what these functions stp?
Reply With Quote
  #4  
Old 26-03-2009
XSI XSI is offline
Member
 
Join Date: May 2008
Posts: 271
Re: Variables of sessions and classes

The sessions can contain resources (like connecting to a comic) or instances of objects. That's why it is so. For objects, the solution is to serialize object: it is the solution given by fellah. As against this solution does not for the resources.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Variables of sessions and classes"
Thread Thread Starter Forum Replies Last Post
How sessions are uniquely identified in ASP.net jEEMOOT Software Development 3 12-01-2011 07:51 PM
Help!! Spring and Hibernate sessions Fragant Software Development 6 15-09-2010 09:40 PM
Sessions with Java Servlets Sheenas Software Development 5 15-02-2010 08:15 PM
What is PHP sessions and how they function Zavier Software Development 5 23-01-2010 02:30 AM
How to set sessions for checkboxes RogerFielden Software Development 3 15-04-2009 02:07 PM


All times are GMT +5.5. The time now is 04:38 PM.