phpwork/timeout.php
2025-03-27 11:34:12 +08:00

40 lines
928 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// 设置时区(根据你的实际时区调整)
date_default_timezone_set('Asia/Shanghai');
// 初始化变量
$last_login = '';
$current_login = date('Y-m-d H:i:s');
// 检查是否存在上次登录时间的Cookie
if(isset($_COOKIE['last_login'])) {
$last_login = $_COOKIE['last_login'];
} else {
$last_login = "这是您第一次访问!";
}
// 设置新的Cookie有效期一周60秒*60分钟*24小时*7天
setcookie('last_login', $current_login, time() + 60*60*24*7, '/');
?>
<!DOCTYPE html>
<html>
<head>
<title>登录时间记录</title>
<meta charset="UTF-8">
</head>
<body>
<h1>登录时间信息</h1>
<?php if($last_login !== '') : ?>
<p>上次登录时间:<?php echo $last_login; ?></p>
<?php endif; ?>
<p>本次登录时间:<?php echo $current_login; ?></p>
<?php if(!isset($_COOKIE['last_login'])) : ?>
<p>欢迎新用户!</p>
<?php endif; ?>
</body>
</html>