-4

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

here is my logout script i want to logout user if the page is inactive for 10 min and send to index.php using header.

<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
$msg = "You have been logout successfully.";
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);

$logoutGoTo = "index.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
Community
  • 1
  • 1
NoPHPknowldege
  • 294
  • 1
  • 10
  • This question might help you: http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes – Guganeshan.T Oct 13 '11 at 07:32

1 Answers1

1

This is done by setting session time out. For example:

$idle = xxx; 
$session_life = time() - $_SESSION['timeout_logout'];
if($session_life > $idle)
{ 
session_destroy(); header("Location: index.php"); 
}
S_SESSION['timeout_logout']=time();
M. Suleiman
  • 858
  • 4
  • 22