Results 1 to 4 of 4

Thread: Variables of sessions and classes

  1. #1
    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?

  2. #2
    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']); 

  3. #3
    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?

  4. #4
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,585,667.82939 seconds with 16 queries