We help IT Professionals succeed at work.

Removing Session Variables on Leaving site.

On login to my website, I create a session variable. I'm trying to find out if there's a way to remove that session variable if the user leaves the web site (ie they close that browser tab or just type in a different url).

After doing some research, I'm afraid there might not be a good answer to this since there's no page request to our site when a user does that, but you guys have surprised me before.
Comment
Watch Question

Director
Commented:
No, its not possible, the session will end when it times out - usually 20 mins. Why would you care?
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
No, not on this one and people ask this all the time.  Like you said, nothing gets sent to the server under those conditions.  Normally sessions use 'session cookies' which expire when the browser is closed but not when just a tab is closed.  The session variables should expire when the session times out.  

The closest anyone has come is a javascript 'pinger' that uses AJAX to let the server know that the window for the session is still open.  What that really does is continuously reset the session timer to extend the session.

Author

Commented:
The person that pays me asked me to do it. Not sure why exactly he would care. Thanks though :)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.