37 lines
847 B
PHP
37 lines
847 B
PHP
<?php
|
|
session_start();
|
|
// 验证Cookie
|
|
if (!isset($_COOKIE['login_time']) || !isset($_COOKIE['username'])) {
|
|
header("Location: login.php");
|
|
exit();
|
|
}
|
|
|
|
$current_time = time();
|
|
$login_time = (int)$_COOKIE['login_time'];
|
|
$remaining = 60 - ($current_time - $login_time);
|
|
|
|
if ($remaining <= 0) {
|
|
// 清除过期Cookie
|
|
setcookie('username', '', time() - 3600, '/');
|
|
setcookie('login_time', '', time() - 3600, '/');
|
|
header("Location: login.php?error=expired");
|
|
exit();
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Welcome</title>
|
|
</head>
|
|
<body>
|
|
<h2>Welcome <?php echo htmlspecialchars($_COOKIE['username']); ?>!</h2>
|
|
<p>Session expires in: <?php echo $remaining; ?> seconds</p>
|
|
<a href="logout.php">Logout</a>
|
|
|
|
<script>
|
|
// 自动刷新剩余时间
|
|
setTimeout(() => location.reload(), 1000);
|
|
</script>
|
|
</body>
|
|
</html>
|