Jump to content

session expire time


woodplease

Recommended Posts

how can i set a session to expire after a set amount of time, say 1 hour.

 

i'm using the following code to create my session, but i dont know what i need to add to make it expire

 

$_SESSION['pageviewsid'.$id] = $new;

 

 

 

$new is the result from a calculation and $id is the page id from the URL using $_GET

 

Link to comment
https://forums.phpfreaks.com/topic/213989-session-expire-time/
Share on other sites

when the session is started, you can set a session variable with the current unix timecode... then check to see if it is more than 1hour past the sign in time...

session_start();

//log in etc etc
//when login authenticated, add this line
$_SESSION['sessionStart'] = time();

 

then in your script where it checks the user is logged in each time a page is viewed, add a line like

if ((time() - $_SESSION['sessionStart']) > 60*60)
{
session_destroy();
exit("Session expired");
}

Link to comment
https://forums.phpfreaks.com/topic/213989-session-expire-time/#findComment-1113653
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.