47 lines
1.6 KiB
PHP
47 lines
1.6 KiB
PHP
<?php
|
||
session_start();
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
$username = $_POST['username'] ?? '';
|
||
$password = $_POST['password'] ?? '';
|
||
|
||
// 默认账号密码设置:admin / admin123
|
||
// 后续建议移动到环境变量或数据库加密存储
|
||
if ($username === 'admin' && $password === 'admin123') {
|
||
$_SESSION['loggedin'] = true;
|
||
$_SESSION['username'] = $username;
|
||
header('Location: admin.php');
|
||
exit;
|
||
} else {
|
||
$error = '账号或密码错误';
|
||
}
|
||
}
|
||
?>
|
||
<!doctype html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<title>登录 - 管理后台</title>
|
||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||
<style>
|
||
body { height: 100vh; display: flex; align-items: center; justify-content: center; background-color: #f8f9fa; }
|
||
.login-card { width: 100%; max-width: 400px; padding: 20px; background: white; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="login-card">
|
||
<h4 class="mb-3">后台登录</h4>
|
||
<?php if (isset($error)): ?><div class="alert alert-danger"><?= htmlspecialchars($error) ?></div><?php endif; ?>
|
||
<form method="POST">
|
||
<div class="mb-3">
|
||
<label class="form-label">账号</label>
|
||
<input type="text" name="username" class="form-control" required>
|
||
</div>
|
||
<div class="mb-3">
|
||
<label class="form-label">密码</label>
|
||
<input type="password" name="password" class="form-control" required>
|
||
</div>
|
||
<button type="submit" class="btn btn-primary w-100">登入</button>
|
||
</form>
|
||
</div>
|
||
</body>
|
||
</html>
|