以下是一个简单的PHP管理员登录示例:
<?php
session_start();
// 检查是否已经登录
if(isset($_SESSION['admin_loggedin']) && $_SESSION['admin_loggedin'] === true){
header("Location: admin_dashboard.php"); // 已登录,重定向到管理员仪表盘
exit;
}
// 检查表单提交
if(isset($_POST['username']) && isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
// 检查用户名和密码是否正确
if($username == 'admin' && $password == 'admin123'){
$_SESSION['admin_loggedin'] = true;
header("Location: admin_dashboard.php"); // 登录成功,重定向到管理员仪表盘
exit;
}else{
$error_message = "用户名或密码错误";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>管理员登录</title>
</head>
<body>
<h2>管理员登录</h2>
<?php if(isset($error_message)): ?>
<p><?php echo $error_message; ?></p>
<?php endif; ?>
<form method="POST" action="">
<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>
<input type="submit" value="登录">
</form>
</body>
</html>
上述代码包含以下步骤:
上一篇:php7数据库记录
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站