Link to home
Start Free TrialLog in
Avatar of Josh_Blade
Josh_Blade

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Dale Burrell
Dale Burrell
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dave Baldwin
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.
Avatar of Josh_Blade
Josh_Blade

ASKER

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