0

这是我在 30 分钟不活动后结束会话的代码,在 Linux 中可以正常工作,但在 Windows 中不行。

创建会话

$_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 } ?>
4

1 回答 1

0

Try to call:

session_cache_expire($max_time);

This will increase the session timeout.

于 2013-02-10T12:33:55.263 回答