feat(登录): 为开发者和管理员登录添加记住我功能
- 在config.php中设置数据库和SMTP的密码 - 在developer/login.php和admin/login.php中添加记住我功能 - 实现30天自动登录的cookie设置
This commit is contained in:
@@ -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 = '用户名或密码错误';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
@@ -106,10 +123,16 @@ if (!isset($_SESSION['admin'])) {
|
||||
<label for="username">用户名</label>
|
||||
</div>
|
||||
<div class="form-floating mb-3">
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
<label for="password">密码</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">登录</button>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
<label for="password">密码</label>
|
||||
</div>
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" type="checkbox" name="remember_me" id="remember_me">
|
||||
<label class="form-check-label" for="remember_me">
|
||||
自动登录
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">登录</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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)) {
|
||||
<input type="password" id="password" name="password" class="form-control" placeholder="请输入密码" required>
|
||||
<label for="password">密码</label>
|
||||
</div>
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" type="checkbox" name="remember_me" id="remember_me">
|
||||
<label class="form-check-label" for="remember_me">
|
||||
自动登录
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">登录</button>
|
||||
</form>
|
||||
<div class="text-center mt-3">
|
||||
|
||||
Reference in New Issue
Block a user