Page 1 of 1

How to force user to login again after 5 minutes ???

Posted: Wed Dec 31, 2003 12:51 am
by tiger
After login for 5 minutes and user didn't do anything, how am I going to force user to login again ?????? :!:

Posted: Wed Dec 31, 2003 1:13 am
by aquila125
why not save the login variable in a session.. and wait for the session to be destroyed...
Or on each page put an update statement for your database with a timestamp on the last_active column, and check that

Posted: Wed Dec 31, 2003 4:57 am
by infolock
sessions or cookies is the way you are gonna want to go with this definately.

[php_man]http://www.php.net/session[/php_man]

Posted: Wed Dec 31, 2003 3:33 pm
by d3ad1ysp0rk
meta refresh url.php?act=logout in 300 seconds??

Posted: Wed Dec 31, 2003 7:20 pm
by drakkon
I do something similar to this in a code that I use. After 2 hours if the user is logged in and hasn't gone to a new page, it loads in the login.php page.

<script language="JavaScript">
<!--
user = "<?=$user?>";
if (user != "Guest"){
setTimeout("top.location.href = 'login.php'",7230000);
}
//-->
</script>

As you can see the user is set to whatever the person is logged in as through the php echo of $user, if they are logged in it will load login.php in 2 hours...

To set it for 5 min would be 300000 since each second is roughly 1000...

Hope this helps

Posted: Wed Dec 31, 2003 9:06 pm
by m3rajk
you can't change time in sessions. to do that you'll have to do something with checking the table. that's why i went with manipulating the cookies directly

Posted: Wed Dec 31, 2003 11:19 pm
by infolock
m3rajk wrote:you can't change time in sessions. to do that you'll have to do something with checking the table. that's why i went with manipulating the cookies directly

no, you can't change times on the fly, but when you you can set a timeout on the session which will self-destruct after a given set # of seconds/minutes, and then leaving the user no longer logged in, and sent back to whatever page it is you want them to go to..

session.cookie_lifetime (which you can also set in your php.ini file ) is a prime example. For 5 minutes, set to 300 seconds, and after 300 seconds, the session is killed.

Posted: Thu Jan 01, 2004 12:55 am
by JAM
Some ideas to play with:

Code: Select all

<?php
    session_start();
    if (!empty($_SESSION['lastseen'])) {
        echo 'Seen: '. (time() - $_SESSION['lastseen']) .'s ago<br>';
 /*
 * If this is say, >5 minutes, destroy sessions, clean variables (or whatever)
 * and header() the user to the login page, as some ideas...
 */
    }
    $_SESSION['lastseen'] = time();
    echo $_SESSION['lastseen'];
?>
Above result:

Code: Select all

Seen: 6s ago
1072939898