这是我在 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 } ?>