SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    May 2007
    Location
    West Midlands, UK
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing Objects In Sessions

    Is this considered o.k to do?

    I have a user object, created when a user has been verified and logs in. I need access to the functions to get data on the user from the database.

    For example, I have an edit details page, which needs to load all the information into inputs.

    Also instead of creating lots of session indexes I could also just use $_SESSION['user']->getUserID(); and stuff.

    Any info on this appreciated.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Yes you can do that...
    Easy no? $_SESSION['user'] = new User();
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The $_SESSION array can contain objects. Note that the object must be defined prior to session_start() so that the object can be properly reconstructed. You might also want to look at the __sleep() and __wakeup() special functions.

    mikem


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
  •