2011-10-13 50 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(); 
相关问题