Automatic Log Out When Browser Closes
Solution 1:
If you work with cookies just don't set an expiration. So the Cookie will be deleted if you close the browser. With Javascript you could try to use the onunload or onbeforeunload event.
JS:
window.onunload = function() {
document.cookie = 'mycookie=myvalue; expires=Thu, 01-Jan-70 00:00:01 GMT;';
};
or maybe you could send a last XHR request in the unload function. But i never tried it so i can't say if it is really going to work.
Solution 2:
If you want to be extra careful, or if you have interactive elements that need proper cleanup, you should use on of the unload events:
Solution 3:
You can bind the window.onunload
event in javascript, possibly to call a PHP script via ajax, but this would be highly unreliable. Whenever the browser shut down ungracefully, for example, the script would not fire. Also it would not fire if javascript were disabled.
Solution 4:
Better reduce the time until a session expires and refresh the session by asynchronly calling a page (via a xhr) which will extend the session.
Post a Comment for "Automatic Log Out When Browser Closes"