An easy session question.

Discussion in 'PHP' started by Jen-, Jul 20, 2007.

  1. #1
    Hello, can you set sessions to expire like you can cookies? If not, how long does a session you set on the server, last?

    Please let me know, thanks a lot. Jen
     
    Jen-, Jul 20, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    ini_set('session.gc_maxlifetime', time() + /* time in seconds */);
    ini_set('session.cookie_lifetime', time() + /* time in seconds */); 
    
    PHP:
     
    nico_swd, Jul 20, 2007 IP
  3. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks a lot, whats the difference between those 2?
     
    Jen-, Jul 20, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    From php.net:

    http://www.php.net/session

    EDIT:

    I'd use 0 for the second, so that it expires on window close.
     
    nico_swd, Jul 20, 2007 IP
  5. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #5
    Most sessions expires after people close their browsers by default. I would set a end_date session variable and then check it each time a user get on the site. If the date > end_date. Then just session_destory the session. but the way sessions work is they set the SID cookie in the browser and you can then use the php cookie settings to set a end date on the SID cookie value for the session.
     
    exodus, Jul 20, 2007 IP
  6. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Good grief, wonder why they can't make it easy like cookies. Maybe someone will know how to help me with my session. How can I set a session expiration on this so that if they close their browser, reopen again, and go back to the same page, the same session will still be remembered? Your instructions sound like just using time() won't work. Please let me know, thank you very much. Jen

    session_start();
    // check if session var is set
    // if not, set it to zero
    // else increase by one
    if(!isset($_SESSION['a']))
    {
    $_SESSION['a'] = 0;
    }else{
    $_SESSION['a']++;
    }
     
    Jen-, Jul 20, 2007 IP