Showing posts with label sign out. Show all posts
Showing posts with label sign out. Show all posts

Friday, March 11, 2011

Gmail style auto logout

Hi,

Assume you are logged into gmail and have opened various instance of gmail, by creating new tab or new window of the same browser. Now when you logout from any one of the instance you get logged out from all the instances. This code does exactly the same. This is how it works:


The idea here is to run a script continously in the backgroud, which always keeps checking the current session status. Whenever it finds that the session doesn't exist, it just redirects the current page to login.php. Javascript is the key, and the function which is making this happen is setTimeout(). Since I have used ajax it will not effect the actual page's performance. This is the code that got the ball rolling: