Page 1 of 1
How to close the session if the user closes the window ?
Posted: Tue Mar 23, 2004 8:42 am
by anjanesh
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
Posted: Tue Mar 23, 2004 8:45 am
by malcolmboston
sessions automatically end when the browser is closed
to solve the problem for the mysql table
run a time function
basically if the time exceeds 2 hours from time logged in, run a query and update the database
this is how its done most of the time i believe
Posted: Tue Mar 23, 2004 9:02 am
by JayBird
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