Sessions ...

Discussion in 'PHP' started by fulltilt, Jan 30, 2009.

  1. #1
    Hi,

    I can't find a definitive answer on this:

    If I use session variables, like ...

    $_SESSION['admin'] = "yes";


    How long does the session last ? In my case the pages will be continually refreshed and used, does that mean that the session will last forever, or I have to set session.cookie_lifetime to 0 and then destroy the session if I don't need it any more ?
     
    fulltilt, Jan 30, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    You can destroy it at your leisure, it will last (typically) for the current browser session.

    Dan.
     
    Danltn, Jan 30, 2009 IP
    fulltilt likes this.
  3. hassanahmad1

    hassanahmad1 Active Member

    Messages:
    150
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #3
    you can destroy it by calling session_destroy()
     
    hassanahmad1, Jan 30, 2009 IP
  4. magiatar

    magiatar Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #4
    The session is per-browser.

    The session auto-destroy depends on php.ini configuration.
    With session.gc_maxlifetime you define the maximum time the session will last.
    (It's not exactly this time, there is a probability system ... but it's a good initial point to think on this time)

    If the user is continually browsing pages, the session will not expire because this time is "reset" on each page.

    Normally, a logout button should include: session_destroy() to directly destroy the session.

    More info:http://es.php.net/manual/en/book.session.php
     
    magiatar, Jan 30, 2009 IP
  5. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #5
    By refreshing and refreshing your session wont get killed untill u will exit browser completely
     
    crivion, Jan 30, 2009 IP
    Foggy likes this.
  6. fulltilt

    fulltilt Peon

    Messages:
    128
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks to all that replied :)

    Basically the session lasts as long as you want, as Danltn stated but to use session_destroy() you also need to use session_start() on the same page.
     
    fulltilt, Jan 30, 2009 IP
  7. bbrez1

    bbrez1 Banned

    Messages:
    208
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You need session_start() anyway, even if you don't use session_destroy().
     
    bbrez1, Jan 31, 2009 IP