循环中的php会话超时?

时间:2011-09-01 14:36:42

标签: php session loops

如何进行循环 - 在会话授权时检查时间是否已过期。我的代码如下所示:

while ($_SESSION['auth']) {
    $inactive = 600;
    if (isset($_SESSION['timeout'])) {
        $session_life = time() - $_SESSION['timeout'];
        if ($session_life > $inactive) {
            session_destroy();
            header("Location: logoutpage.php");
        }
    }
}

2 个答案:

答案 0 :(得分:0)

这样做会让你陷入困境一段时间..

但总而言之,你现在拥有的循环应该有效。

答案 1 :(得分:0)

好的,我已经做了以下事情,也许它可以帮助其他人:

<强>第1页

session_start();
///
$teststart = 3600;
$now = time();
$testend = ($now + $teststart);
define(testend1,$testend);
$_SESSION['now2'] = $now;
$_SESSION['testend2'] = testend1;
header('Location:http://localhost/index.php?option=com_content&view=article&id=51');

<强>第2页

头部分中的

以便页面刷新

<meta http-equiv="refresh" content="300">

然后在第2页

session_start();
if ($_SESSION['auth']) {
$session_testend3 = $_SESSION['testend2'];
$now = time();
if ($now > $session_testend3) {
session_destroy();
header('Location: http://localhost/');
  exit;
}
}else{
echo "you are not authorized";
}