Jump to content

Time limit on session


smc

Recommended Posts

Here is what did:

[code]
<?php

//No session set (first time user visited)
if(empty($_SESSION['last_active'])){
//Set the Session
$_SESSION['last_active'] = time();
}

//Session set, but user not active for more than thirty minutes
elseif(!empty($_SESSION['last_active']) && $_SESSION['last_active'] < time()-7200){

print "You must be logged in to view this page. <a href='index.php'>Login here.</a>";

//Destroy the session
$_SESSION['last_active'] = '';
exit;
}

//Session set, and the user has been active for under thirty minutes
elseif(!empty($_SESSION['last_active']) && $_SESSION['last_active'] >= time()-1800){
//Update session with current time
$_SESSION['last_active'] = time();
}

?>
[/code]

Put this on your header.php page so it executes every time somone clicks. I changed it for you so it keeps them logged in for 2 hours.
Link to comment
https://forums.phpfreaks.com/topic/35172-time-limit-on-session/#findComment-166076
Share on other sites

  • 2 years later...

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.