Login.php的代码部分
else if( ($row['Password'] == md5($pass)) ){
$_SESSION['user'] = $row['FName'];
$_SESSION['last_activity'] = time();
header("Location: welcome.php");
}
welcome.php的整个代码
<?php
session_start();
if( !isset($_SESSION['user']) ){ //session verification
header("Location: login.php");
}
else{
echo "Welcome, ". $_SESSION['user']. "<br>";
echo "<a href='logout.php'> Logout </a>";
}
if( $_SESSION['last_activity'] < (time() - 600) ){ //time in seconds, 10 minutes
session_destroy();
header("Location: login.php");
exit;
}
else{
$_SESSION['last_activity'] = time();
}
&GT;
问题:即使我在10分钟后刷新页面,welcome.php页面仍然保持登录状态。有什么问题?感谢
答案 0 :(得分:1)
试试这个;
$last_activity = time() - $_SESSION['last_activity'];
if( $last_activity >= 600 ){ //time in seconds, 10 minutes
session_destroy();
header("Location: login.php");
exit();
}