How to close the session if the user closes the window and not chooses to logout ? I store the session is a table but they get removed only when logging out. But many times the users don't log out - they just close the window. In that case how do I get session_destroy() to work ?
Thanks
How to close the session if the user closes the window ?
Moderator: General Moderators
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
It is a pain in the ass.
Javascript is the way to go.
Unfortunately there isn't a window.onClose function in the Javascript specification and is only implemented by Some versions of Netscape.
So...
a solution i used (and probably the only solution) is to use the onUnload function
The problem with onUnload is that the functions is executed when the user navigates from page to page WITHIN the site...which is obviously no good.
To get around this...
Load the site using frames, one which is like 1 pixel in height and the other fills the rest of the screen. In the 1 pixel frame, load a html/php file that has onUnload in the body tag. When the user closes the broser window, the a pop-up window appears executing a "hard" log-out.
When the user is navigating the site as normal, the html/php file in the 1 pixel frame never changes, therefor not calling the onUnload event.
Mark
Javascript is the way to go.
Unfortunately there isn't a window.onClose function in the Javascript specification and is only implemented by Some versions of Netscape.
So...
a solution i used (and probably the only solution) is to use the onUnload function
The problem with onUnload is that the functions is executed when the user navigates from page to page WITHIN the site...which is obviously no good.
To get around this...
Load the site using frames, one which is like 1 pixel in height and the other fills the rest of the screen. In the 1 pixel frame, load a html/php file that has onUnload in the body tag. When the user closes the broser window, the a pop-up window appears executing a "hard" log-out.
When the user is navigating the site as normal, the html/php file in the 1 pixel frame never changes, therefor not calling the onUnload event.
Mark