这是我在30分钟不活动后结束sessionón的代码,在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 } ?>
尝试调用:
session_cache_expire($max_time);
这将增加会话超时。