Forum Moderators: coopster

Message Too Old, No Replies

Destroying a session on timer

         

briesm

6:17 pm on Jun 3, 2005 (gmt 0)

10+ Year Member



Anyone know how I could destroy a session and redirect to a session timed out page say in like 5 minutes of not submitting a form?

jatar_k

6:21 pm on Jun 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



put a unix timestamp in the session when they login

every time they hit a page, generate a new timstamp and compare it to the one in the session

if difference is greater than 300 use header to send them to login page with time out message

briesm

6:45 pm on Jun 3, 2005 (gmt 0)

10+ Year Member



Yea, but can I get it to redirect them and destroy the session automatically? It seems like otherwise they may continue to fill out the form and not realize they are timed out...
This script does it, but obviously holds up loading the page because the while loop is infinite until 60 seconds.
$timeout = time() + (60);
while (time() <= $timeout) {
if(time() == $timeout) header("Location: http://www.example.com");
}

[edited by: jatar_k at 8:25 pm (utc) on June 3, 2005]
[edit reason] examplified url [/edit]

jatar_k

8:30 pm on Jun 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you mean while they are sitting filling out the form, then no, not with php

php is a server side language which means they can have that page open for as long as they want and php will know nothing about it until it is sent back to the server.

There may be a javascript soution for this.

actually, you could have a really long meta refresh too, I guess, not really sure why you would want ot do all this though. Why is it so time sensitive?