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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    169
    Thanks
    26
    Thanked 3 Times in 3 Posts

    Destroying session on browser tab close

    I understand that session data is only destroyed when the user completely exits the browser. However, the data remains intact if the user only exits out of the tab in the browser. Is there any piece of code which would destroy a session when exiting a tab? I tried Googling this, but I couldn't find anything.

    Thanks!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    No.
    You may be able to implement a javascript method to handle it, but I don't know if there is an ontabclose or anything like that. I haven't used JS since before tabbed browsing.
    So long as the browser is running, it will not delete session based (temporary) cookies.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    What is the purpose of this? It may be possible to accomplish what you want indirectly, for instance by keeping a timer since last page load or something and destroying the session if the timer passes a certain time.

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Even if you were to implement some sort of JavaScript solution, you could never actually depend on it working. Browsers crash, some people don't have JavaScript enabled, the browser is left open and the session times out, etc. Basically you just don't know for sure, so you just have to wait for their session to expire on the server.
    OracleGuy


  •  

    Posting Permissions

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