30分钟后脚本到会话超时,在Windows中不起作用

时间:2013-02-10 12:29:27

标签: php session-timeout

这是我在30分钟不活动后结束sessión的代码,在Linux中工作正常但在Windows中没有。

创建sessión

$_SESSION['clientdan']['user'] = $username;
$_SESSION['clientdan']['tl'] = time();

any_file.php

<?php
session_start();
$max_time = 1800;
$current = time();

if(!isset($_SESSION['clientdan']['user']) ) {
    header('Location: index.php');
} else {
    if (!isset($_SESSION['clientdan']['tl'])){
        $_SESSION['clientdan']['tl'] = time();
    } else {
        $session_life = $current - $_SESSION['clientdan']['tl'];

        if ($session_life > $max_time) {
            header('Location: include/logout.php');
        } else {
            $_SESSION['clientdan']['tl'] = time();
        }
    }
?>
<!DOCTYPE html>
......
......
<?php } ?>

1 个答案:

答案 0 :(得分:0)

尝试致电:

session_cache_expire($max_time);

这会增加会话超时。