Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    UK
    Posts
    177
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Session not being remembered

    I'm finding that sessions get deleted after the browser is closed (or after some time), despite using:

    session_set_cookie_params(60*60*24*365);
    session_start();

    Any ideas why?

    This is in the latest version of Firefox.

    Stu
    if ($ENV{'QUERY_STRING'} eq "Afrow UK") {
    print "$ENV{'QUERY_STRING'} rocks!";
    } else {
    print qq~$ENV{'QUERY_STRING'} sucks :)~;
    }

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,049
    Thanks
    2
    Thanked 317 Times in 309 Posts
    Assuming that sessions are functioning using cookies to store the session ID (session_start is actually creating/restarting a session and you can browse between pages and access session variables) there are two things (three if you count code that deliberately destroys a session) that can cause a session to be deleted. The session cookie lifetime (which the code you posted should be taking care of) and session data garbage collection.

    Have you determined that the session cookie exists in the cookie folder after the browser is closed?

    If your web server is busy or you are on a busy shared hosting web server and/or someone has set a small garbage collection max life time (you won't believe how many times I have seen posts where someone wants to use a short garbage collection time to log people out instead of using proper code), you will see any session data files that are older than session.gc_maxlifetime being deleted every session.gc_probability/session.gc_divisor session_start() statements.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    I have no idea why. What have you done to debug?

    When it comes to cookies I find the LiveHTTPHeaders extension for Firefox invaluable. Have you tried that? You should be able to clearly see the cookie parameters being sent via the HTTP header.

    Also I use the Web Developer Extension for Firefox. This provides a better interface for viewing/deleting cookies.

    Context: CFMaBiSmAd posted while I was writing this.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •