1

I am new to php coding, and i would really like to figure this login script out.
In my index.php file i have this code

<?Php
session_start();
include 'check.php';}
?>

in my check.php file i have this code

<?Php
if((isset($_SESSION['userid']) and strlen($_SESSION['userid']) > 4)){

echo "";
}else{
header("Location: login.php");
die();
exit;}
?>

How do i create a timeout function to redirect to logout.php after 1 hour?

  • Possible duplicate from http://stackoverflow.com/questions/3068744/php-session-timeout or http://stackoverflow.com/questions/8311320/how-to-change-the-session-timeout-in-php – hherger Feb 11 '16 at 11:38
  • 1
    Possible duplicate of [How do I expire a PHP session after 30 minutes?](http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes) – maxhb Feb 11 '16 at 11:43

1 Answers1

1

The best solution is to implement a session timeout of your own.

$_SESSION['LAST_ACTIVITY']=time();
$_SESSION['userid']='Your ID';

and add this,

<?Php
  session_start();
  if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
     // last request was more than 30 minutes ago
     session_unset();     // unset $_SESSION variable for the run-time 
     session_destroy();   // destroy session data in storage
}
  include 'check.php';}
?>
Rogin Thomas
  • 672
  • 8
  • 17