SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    May 2004
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    objects not persisting in session in CGI PHP

    hey guys, another question that is bugging me at the moment, in fact it has been all day.

    I have a regular shopping cart application, with the session storing a user object and a cart object. the objects are instantiated in exactly the same way, when the application requests these it checks to see if they're set, if not it loads default objects for them (i.e. a user object with guest-level privileges and an empty cart).

    the problem I'm experiencing is the following: when I add an object to the cart it is placed in the cart successfully but not preserved across requests. that is, if I dump the contents of the session before the end of the script the cart has been populated, but after the header() redirect to the next page the cart entry in the session is set to null! the user object is preserved perfectly, even if that user was logged into a specific account.

    a bit of reading has uncovered that I need to define the __sleep method for any objects which will be stored in the session. even doing this however, doesn't work. yet the user object is preserved without needing the __sleep method!

    what's more, this only fails on my remote server, it works fine locally. the difference between the servers is that the remote server has PHP as a CGI whereas my local server has it installed as an apache module.

    I am using a custom session handler which writes to a database. it is working fine in all other respects!

    any help is greatly appreciated as I am fairly stumped.

  2. #2
    SitePoint Zealot
    Join Date
    May 2004
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one more thing - the difference between the shopping cart and the user objects, if it's significant is that the user object stores simple textual data whereas the cart will store CartEntry and Product objects as well. I tried adding a __sleep method to all of these objects but still the same problem.

    all these class definitions are imported before the session is started!

    lastly I should also say that an entry for the cart object is created in the session, it just contains a null value i.e. $_SESSION['cart'] returns null.

  3. #3
    SitePoint Zealot
    Join Date
    May 2004
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well I seem to have fixed it - one of the stored objects had another object as an instance variable I had to set to null for it to work - not sure why? that object (the instance var)'s class was imported before the session started..


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
  •