Jump to content

session end?


phpwiz

Recommended Posts

//put this code on all your pages

session_start();

//10 minutes
$timelimit = 600;

//check if he's been inactive for more than the time limit
if(time() - $_SESSION['timeout'] > $timelimit)
{
  //destroy session and bring him to the login page if he is out of time
  session_destroy(); header("Location: login.php"); 
}

//reset his time if he hasn't timed out yet
$_SESSION['timeout'] = time();

Link to comment
https://forums.phpfreaks.com/topic/169512-session-end/#findComment-894374
Share on other sites

//In theory, you'd run this script on every page.
//Keep in mind, this is a rough draft. You need to tailor it to your liking.
$time = time(); //Declare current time as variable.

//Obviously you must create the table first, with whatever fields you'd like.
$result = mysql_query('SELECT `lastClick` FROM `table` WHERE `user` = \'' . $user . '\''; //Check the last activity.
$lastClick = mysql_result($result, 0); //Make it into a variable.
$lastClickPlusTen = $lastClick + 600; //Calculate time ten minutes from then.

if ($time > $lastClickPlusTen)
{
//If it's been over ten minutes, destroy the session.
session_destroy()
}
else
{
//If it's been less than ten minutes, update this as the new time.
mysql_query('UPDATE `table` SET `lastClick` = \'' . $time . '\' WHERE `username` = \'' . $username . '\'' OR die(mysql_error());
}

 

EDIT: ...nevermind that. Using a session is much smarter. ;)

Link to comment
https://forums.phpfreaks.com/topic/169512-session-end/#findComment-894377
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.