From c101802dfa4ac7b63227bb93f239b3d179a9633e Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Tue, 15 Jul 2025 17:39:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=99=BB=E5=BD=95):=20=E4=B8=BA=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E8=80=85=E5=92=8C=E7=AE=A1=E7=90=86=E5=91=98=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=B7=BB=E5=8A=A0=E8=AE=B0=E4=BD=8F=E6=88=91=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在config.php中设置数据库和SMTP的密码 - 在developer/login.php和admin/login.php中添加记住我功能 - 实现30天自动登录的cookie设置 --- admin/login.php | 49 +++++++++++++++++++++++++++++++++------------ developer/login.php | 23 +++++++++++++++++++++ 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/admin/login.php b/admin/login.php index 7a1bdd0..62a1f60 100644 --- a/admin/login.php +++ b/admin/login.php @@ -11,15 +11,32 @@ if (!isset($_SESSION['admin'])) { $password = $_POST['password']; if ($username === ADMIN_USERNAME && $password === ADMIN_PASSWORD) { - $_SESSION['admin'] = [ - 'id' => 1, // 配置文件中未定义管理员ID,使用默认值1 - 'username' => $username - ]; - header('Location: index.php'); - exit(); - } else { - $error = '用户名或密码错误'; - } + $_SESSION['admin'] = [ + 'id' => 1, // 配置文件中未定义管理员ID,使用默认值1 + 'username' => $username + ]; + + // 处理自动登录 + if (isset($_POST['remember_me']) && $_POST['remember_me'] === 'on') { + $cookie_lifetime = 30 * 24 * 60 * 60; // 30天 + $cookie_params = session_get_cookie_params(); + setcookie( + session_name(), + session_id(), + time() + $cookie_lifetime, + $cookie_params['path'], + $cookie_params['domain'], + $cookie_params['secure'], + $cookie_params['httponly'] + ); + ini_set('session.gc_maxlifetime', $cookie_lifetime); + } + + header('Location: index.php'); + exit(); + } else { + $error = '用户名或密码错误'; + } } ?> @@ -106,10 +123,16 @@ if (!isset($_SESSION['admin'])) {
- - -
- + + + +
+ + +
+ diff --git a/developer/login.php b/developer/login.php index 48b746b..ce216bb 100644 --- a/developer/login.php +++ b/developer/login.php @@ -68,6 +68,23 @@ if (!($conn instanceof mysqli)) { if ($developer && password_verify($password, $developer['password'])) { $_SESSION['developer_id'] = $developer['id']; $_SESSION['developer_username'] = $developer['username']; + + // 处理自动登录 + if (isset($_POST['remember_me']) && $_POST['remember_me'] === 'on') { + $cookie_lifetime = 30 * 24 * 60 * 60; // 30天 + $cookie_params = session_get_cookie_params(); + setcookie( + session_name(), + session_id(), + time() + $cookie_lifetime, + $cookie_params['path'], + $cookie_params['domain'], + $cookie_params['secure'], + $cookie_params['httponly'] + ); + ini_set('session.gc_maxlifetime', $cookie_lifetime); + } + header('Location: dashboard.php'); exit; } else { @@ -125,6 +142,12 @@ if (!($conn instanceof mysqli)) { +
+ + +