帮我写一个后台登录页面
时间: 2023-08-20 08:13:04 浏览: 41
好的,以下是一个简单的后台登录页面的代码。
HTML 代码:
```
<!DOCTYPE html>
<html>
<head>
<title>后台登录</title>
</head>
<body>
<h1>后台登录</h1>
<form action="login.php" method="post">
<label for="username">用户名:</label>
<input type="text" name="username" id="username" required><br>
<label for="password">密码:</label>
<input type="password" name="password" id="password" required><br>
<input type="submit" value="登录">
</form>
</body>
</html>
```
PHP 代码(login.php):
```
<?php
// 检查用户名和密码是否正确
if ($_POST['username'] === 'admin' && $_POST['password'] === '123456') {
// 登录成功,跳转到后台首页
header('Location: admin.php');
exit;
} else {
// 登录失败,返回登录页面
header('Location: login.html');
exit;
}
?>
```
这个登录页面很简单,用户名和密码都是硬编码在代码中的。在实际应用中,应该将用户名和密码保存在数据库中,然后在登录时进行验证。另外还需要对用户提交的数据进行安全性检查,避免 SQL 注入等攻击。
希望这些信息能对你有帮助。