1

Possible Duplicate:
How do I expire a PHP session after 30 minutes?

I have a session

$_SESSION['uid'];

Is there a simple script to end this session after 30 minutes? Any help is greatly appreciated.

Community
  • 1
  • 1
user547794
  • 14,263
  • 36
  • 103
  • 152
  • 2
    not a duplicate, there is a difference between a "session variable" and a "session", their expiration are two different topics –  Aug 16 '16 at 13:36

1 Answers1

4
// Inialize session
session_start('admin');
// set timeout period in seconds
$inactive = 30;
// Check, if user is already login, then jump to secured page
if (isset($_SESSION['admin'])) {
    $session_life = time() - $_SESSION['admin'];
    // Jump to secured page
    header('Location: securedpage.php');
    if($session_life > $inactive) {
        session_destroy();
        // Jump to Logout page
        header("Location: logout.php");
    }
}
$_SESSION['timeout'] = time();
Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
Kannan
  • 105
  • 1
  • 11
  • 3
    PHP - set session variable to expire after 30 minutes $inactive = 30; // the value in seconds. For 30 minutes. $inactive = 1800; – Kannan May 19 '12 at 07:42