Ajax PHP Session Timeout - Automatic Logout

Not open for further replies.
As the title suggests I'm looking to implement the facility whereby a user with a current PHP Session (which has a timeout period) is automatically logged out (redirected to login screen) once the session has timed out.

E.g. a user actively logs in to some web based system. They now have a valid PHP SESSION. This session has a lifetime. The user does not do anything before the session expires and then they try to make some ajax call. The ajax call can check the validity of the session, and see that it has expired, but I would prefer that if the session lasts 20 mins, and the user comes back at 21 mins, they will find the login screen in front of them as opposed to them trying to do something and then they get redirected back to the login screen.

From looking online people suggest the following.

1) Poll the server
Every min or so have javascript ping the server to keep the session alive, so the session doesn't die.

2) Mirror the server clock on the client side
Using Javascript check the session value when the page loads and then init a javascript clock to call a local redirect method when that period of time elapses.

I would prefer not to take either of those approaches. I know what I'm describing is sort of like a pushlet where the server asynchronously tells the browser to leave when the session expires. Actually I just looked up a banks mechanism for doing it and they just use ****in meta redirects after so many seconds. :eek:

Any help appreciated ;)
Not open for further replies.
Award-winning Mac antivirus and Internet security software