SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Session wont destroy

    I built this shopping cart based off the session id. When the person checks out the script clears out the session by destroying it. The problem is it wont delete no matter what I do. The way it works is when you checkout and click on complete order, it forwards you to a page that kills the session with session_destroy. I also tried unsetting the session, setting the session to an empty array and session_unregister. No luck. As long as I keep the window open and go back to the website it still shows whats in the shopping bag.

    I am using ob_start() on the main pages, but I removed the code to see if that was the issue, and it isnt. Is the php config causing the session to keep the session id cached? If so is there a way to clear all session cache?

    Thank you
    Silly

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To delete session data, you must re-start the session first with session_start(), and this must be output at the start of your script before any 'body' data gets sent to the browser. Otherwise the session data will hang around until the session.gc_maxlifetime ini setting has reached its limit (which is 24 minutes by default).

    Hope that helps.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2005
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The session_id is probably being stored in a cookie if not in the url. So you will need to use setcookie() or something to destroy the cookie.

  4. #4
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I do start the session before destroying it. I will see about the cookie.

    Thanks
    Silly

  5. #5
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did a vardump of the $_COOKIE superglobal and it does show PHPSESSID. I tried to expire/delete the cookie but it still wont work! It still vardumps as the same session id unless I close out of the browser and go back in. Very weird.

    Thanks
    Silly

  6. #6
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thinking it was due to the ob_start and end flush issue I took that code out completely. Here is the weird problem, if I go to one page and tell it to destroy the session and blank out the cookie, the shopping bag empties. But then if I go to the next page with no code to destroy session or blank out cookie, the shopping bag reappears with the same session id it previously had before it was deleted. Any ideas?

    Thanks
    Silly


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
  •