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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tiger
Forum Newbie
Posts: 1
Joined: Wed Dec 31, 2003 12:51 am

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

Post by tiger »

After login for 5 minutes and user didn't do anything, how am I going to force user to login again ?????? :!:
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post 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
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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]
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

meta refresh url.php?act=logout in 300 seconds??
drakkon
Forum Newbie
Posts: 3
Joined: Wed Dec 31, 2003 11:51 am

Post 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
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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
Post Reply