2011-10-13 79 views
-4

可能重複:
How do I expire a PHP session after 30 minutes?我如何在PHP如果閒置10分鐘,使用會話註銷用戶

這裏是我的註銷腳本我想註銷用戶如果頁面不活躍10分鐘並使用標題發送到index.php。

<?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; 
} 
} 
?> 
+0

此問題可能會幫助您:http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes –

回答

0

這是通過設置會話超時完成的。例如:

$idle = xxx; 
$session_life = time() - $_SESSION['timeout_logout']; 
if($session_life > $idle) 
{ 
session_destroy(); header("Location: index.php"); 
} 
S_SESSION['timeout_logout']=time(); 
相關問題