View Full Version : Session Timeout Help

06-30-2007, 11:32 AM
Hello all,

I have had problems with getting Session Timeouts to work the way I think they should in PHP. (PHP5) Please help me obtain the following:

Note: All pages on my site call a PHP page where i can put the session script I need help creating.

I want to do the following:
- Session times out after 1 hours of inactivity. (Not changing pages or running AJAX.)
- After 5 and a half hours from the first log in, if the user is still active, prompt them to log in again and start thier session timer over winthout clearing thier session data.
- If they have not logged back in, at the 6 hour mark, thier session is terminated.

The reasoning for this is the application I am creating is a Web Application which could very well be left open on someones machine for an entire day or longer. So if through the day that are using the application, i want them to be able to restart thier session timer without losing thier session data. However I need it to log them out after 6 hours for security.

Any help?

06-30-2007, 10:52 PM
You need to store two timestamps: login timestamp, and lastActivity timestamp. Each page includes a function that check lastActivity and logs the user out (destroys the session) if it is more than 1 hour ago, and checks login timestamp and logs the user out if it is more than 6 hours ago. The function then updates the lastActivity timestamp.