How to force user to login again after 5 minutes ???
Moderator: General Moderators
How to force user to login again after 5 minutes ???
After login for 5 minutes and user didn't do anything, how am I going to force user to login again ?????? 
sessions or cookies is the way you are gonna want to go with this definately.
[php_man]http://www.php.net/session[/php_man]
[php_man]http://www.php.net/session[/php_man]
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
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
<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
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.
Some ideas to play with:
Above result:
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'];
?>Code: Select all
Seen: 6s ago
1072939898