<!-- login.php -->

发布日期:

<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>管理员登录</title>
</head>
<body>
<h2>管理员登录</h2>
<form method="POST" action="login.php">
<label for="username">用户名:</label>
<input type="text" id="username" name="username" required><br><br>

<label for="password">密码:</label>
<input type="password" id="password" name="password" required><br><br>

<button type="submit">登录</button>
<a href="logout.php">退出登录</a>
</form>
</body>
</html>
<?php
session_start();

// 预设管理员用户名和密码
$admin_username = "q1847";
$admin_password = "lxx234561"; // 请务必改为更强的密码!

// 如果表单被提交
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];

// 验证用户名和密码
if ($username === $admin_username && $password === $admin_password) {
$_SESSION['admin_logged_in'] = true;
header("Location: view_articles.php"); // 登录成功后跳转到文章列表
exit;
} else {
echo "用户名或密码错误!";
}
}
?>
<!-- login.php -->
返回文章列表 返回首页