php session_start(); if(isset($_SESSION['admin'])) { header("Location: admin.php"); exit; } if($_SERVER['REQUEST_METHOD'] == 'POST') { require_once 'config.php'; $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); $username = $_POST['username']; $password = $_POST['password']; $stmt = $conn->prepare("SELECT id, password FROM users WHERE username = ?"); $stmt->bind_param("s", $username); $stmt->execute(); $result = $stmt->get_result(); if($user = $result->fetch_assoc()) { if(password_verify($password, $user['password'])) { $_SESSION['admin'] = $user['id']; header("Location: admin.php"); exit; } } $error = "用户名或密码错误"; $conn->close(); } ?> 管理员登录

管理员登录