新增 install.php:全新部署时自动接管,用户只需上传文件、打开站点即进入
安装向导。安装页自己做三件事:
- 建 db/ 与 uploads/{posters,tickets,photos,avatars}/,权限调到 775
- 逐目录真写临时文件实测可写,不靠 is_writable 猜
- 建库、建管理员、写 db/.installed 锁、自删本文件
配套改动:
- config.php 把安装检查前置于建库之前,未安装一律 302 到 install.php。
原实现无条件调用 initDB(),导致「打开首页」就等于建库并种下 admin/123456。
- lib/db.php 的 initDB(\$seedDefaultAdmin = true);安装向导传 false,
管理员由用户自己设,绝不种弱口令。新增 isInstalled()。
- login.php / nav.php 接上 siteName(),站点名称不再只存不用。
- lib/settings.php 新增 siteName(),缺省回退「电影日志」。
PHP 8.5 兼容:
- 删掉 fetch_movie.php 与 lib/storage/http.php 的 curl_close()。
8.5 起该函数 deprecated,调用会往输出插一行警告,把 JSON 响应污染成
「警告 + JSON」,前端 JSON.parse 失败 → 电影名联想功能完全失灵。
- config.php 的 display_errors 由 1 改为 0(生产环境不应向浏览器吐错误),
错误仍写日志;需要调试时设 MOVIELOG_DEBUG=1 打开。
线上验证(movie.yangyq.net,PHP 8.5.12):
未安装时 / 、/login.php 均 302 → install.php;
安装页 200、体检 10/10 通过、自动建好 5 个目录;
安装后 install.php 404、管理员登录成功、首页 200 无报错;
联想接口带会话请求「流浪地球/星际穿越/霸王别姬」均返回纯 JSON(首字符 {)。
202 lines
6.2 KiB
PHP
202 lines
6.2 KiB
PHP
<?php
|
|
// ============================================
|
|
// 文件: login.php
|
|
// 说明: 管理员登录页面
|
|
// ============================================
|
|
|
|
require_once 'config.php';
|
|
|
|
// 如果已登录,跳转到首页
|
|
if (isset($_SESSION['admin_id'])) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = trim($_POST['username'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if (empty($username) || empty($password)) {
|
|
$error = '请输入用户名和密码';
|
|
} else {
|
|
$db = getDB();
|
|
$stmt = $db->prepare("SELECT * FROM admins WHERE username = ?");
|
|
$stmt->execute([$username]);
|
|
$admin = $stmt->fetch();
|
|
|
|
if ($admin && password_verify($password, $admin['password'])) {
|
|
$_SESSION['admin_id'] = $admin['id'];
|
|
$_SESSION['admin_username'] = $admin['username'];
|
|
// 把他自己选的界面主题一起带进会话(空 = 用默认主题)
|
|
$_SESSION['admin_theme'] = isset($admin['theme']) ? (string)$admin['theme'] : '';
|
|
header('Location: index.php');
|
|
exit;
|
|
} else {
|
|
$error = '用户名或密码错误';
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="zh-CN"<?= themeAttr() ?>>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?= h(siteName()) ?> - 登录</title>
|
|
<link rel="stylesheet" href="css/style.css">
|
|
<?= themesCssLink() ?>
|
|
<style>
|
|
/* 登录页专用样式 */
|
|
body {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
min-height: 100vh;
|
|
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
|
|
margin: 0;
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
}
|
|
.login-container {
|
|
background: rgba(255,255,255,0.05);
|
|
backdrop-filter: blur(20px);
|
|
-webkit-backdrop-filter: blur(20px);
|
|
border: 1px solid rgba(255,255,255,0.1);
|
|
border-radius: 24px;
|
|
padding: 48px 40px;
|
|
width: 100%;
|
|
max-width: 400px;
|
|
box-shadow: 0 30px 80px rgba(0,0,0,0.5);
|
|
transition: transform 0.3s ease;
|
|
}
|
|
.login-container:hover {
|
|
transform: translateY(-4px);
|
|
}
|
|
.login-logo {
|
|
text-align: center;
|
|
margin-bottom: 36px;
|
|
}
|
|
.login-logo .icon {
|
|
font-size: 52px;
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
}
|
|
.login-logo h1 {
|
|
color: #fff;
|
|
font-size: 28px;
|
|
font-weight: 700;
|
|
margin: 0;
|
|
letter-spacing: 2px;
|
|
}
|
|
.login-logo p {
|
|
color: rgba(255,255,255,0.5);
|
|
font-size: 14px;
|
|
margin: 6px 0 0;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
.form-group label {
|
|
display: block;
|
|
color: rgba(255,255,255,0.7);
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
margin-bottom: 6px;
|
|
}
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 14px 18px;
|
|
background: rgba(255,255,255,0.08);
|
|
border: 1px solid rgba(255,255,255,0.12);
|
|
border-radius: 12px;
|
|
color: #fff;
|
|
font-size: 16px;
|
|
transition: all 0.3s ease;
|
|
box-sizing: border-box;
|
|
outline: none;
|
|
}
|
|
.form-group input:focus {
|
|
border-color: var(--primary);
|
|
background: rgba(255,255,255,0.12);
|
|
box-shadow: 0 0 0 4px rgba(var(--primary-rgb),0.15);
|
|
}
|
|
.form-group input::placeholder {
|
|
color: rgba(255,255,255,0.3);
|
|
}
|
|
.btn-login {
|
|
width: 100%;
|
|
padding: 14px;
|
|
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
|
border: none;
|
|
border-radius: 12px;
|
|
color: #fff;
|
|
font-size: 18px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
margin-top: 8px;
|
|
letter-spacing: 1px;
|
|
}
|
|
.btn-login:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 10px 30px rgba(var(--primary-rgb),0.3);
|
|
}
|
|
.btn-login:active {
|
|
transform: translateY(0);
|
|
}
|
|
.error-msg {
|
|
background: rgba(231,76,60,0.2);
|
|
border: 1px solid rgba(231,76,60,0.3);
|
|
color: #e74c3c;
|
|
padding: 12px 16px;
|
|
border-radius: 10px;
|
|
font-size: 14px;
|
|
margin-bottom: 16px;
|
|
text-align: center;
|
|
}
|
|
.login-footer {
|
|
text-align: center;
|
|
margin-top: 24px;
|
|
color: rgba(255,255,255,0.3);
|
|
font-size: 13px;
|
|
}
|
|
@media (max-width: 480px) {
|
|
.login-container {
|
|
padding: 32px 24px;
|
|
margin: 16px;
|
|
border-radius: 16px;
|
|
}
|
|
.login-logo h1 {
|
|
font-size: 24px;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<div class="login-logo">
|
|
<span class="icon">🎬</span>
|
|
<h1><?= h(siteName()) ?></h1>
|
|
<p>记录每一帧感动</p>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="error-msg"><?= h($error) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" action="">
|
|
<div class="form-group">
|
|
<label>管理员账号</label>
|
|
<input type="text" name="username" placeholder="请输入用户名" value="<?= h($_POST['username'] ?? '') ?>" autofocus>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>密码</label>
|
|
<input type="password" name="password" placeholder="请输入密码">
|
|
</div>
|
|
<button type="submit" class="btn-login">登 录</button>
|
|
</form>
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|