【问题标题】:PHP - set session variable to expire after 30 minutes [duplicate]PHP - 将会话变量设置为在 30 分钟后过期 [重复]
【发布时间】:2011-07-01 14:36:36
【问题描述】:

可能重复:
How do I expire a PHP session after 30 minutes?

我有一个会话

$_SESSION['uid'];

是否有一个简单的脚本可以在 30 分钟后结束此会话?非常感谢任何帮助。

【问题讨论】:

  • 不是重复的,“会话变量”和“会话”是有区别的,它们的过期是两个不同的主题

标签: php


【解决方案1】:
// 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();

【讨论】:

  • PHP - 设置会话变量在 30 分钟后过期 $inactive = 30; // 以秒为单位的值。 30分钟。 $inactive = 1800;
猜你喜欢
  • 1970-01-01
  • 2010-10-05
  • 1970-01-01
  • 2011-04-15
  • 1970-01-01
  • 2017-05-17
相关资源
最近更新 更多