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
    Jun 2005
    Posts
    153
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Timed Session Kill

    Hello Everyone,

    I would like to have My $_SESSION variable destroyed after a certain amount of time. Is there a way that I can have a timeout function or something that after 10 minutes it will destroy this variable?

    Thanks
    -questionable

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The way I know of is to store a timestamp in the $_SESSION array and then with each page load check that timestamp and if the time difference is greater than your 10 minutes (or whatever) then destroy the session (and redirect or whatever). It won't "officially" be destroyed until the page is reloaded though; in other words, it won't be right on the 10 minute mark, and if the page never gets reloaded then the session won't be explicitly destroyed (but will expire as all sessions eventually do).

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Another thing you might be able to do is set the max lifetime in htaccess to 10 minutes. The only down side of this is it will effect all sessions on your site. This is what I use in one of the htaccess files on a site I'm in charge of
    Code:
    php_value session.gc_maxlifetime 2419200
    php_value session.cookie_lifetime 604800
    I believe its set for a week or something like that.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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