我正在为我的学校项目创建一个登录系统,并且在验证密码时卡住了。它没有给出任何错误,但是没有用。
我试图修改代码结构,但无济于事。
session_start();
$username = "root";
$password = "password";
$database = "database";
$mysqli = new mysqli("localhost", $username, $password, $database);
if($_SERVER["REQUEST_METHOD"] == "POST"){
$username = trim($_POST["username"]);
$password = trim($_POST["password"]);
echo $username;
echo $password;
$query = "SELECT * FROM `users` WHERE `username` = '$username'";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
if(password_verify($password, $row["password"])) {
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $row["id"];
echo "xd";
header("location: /index.php");
}
}
/*free resultset*/
$result->free();
}
它将在会话中将我重定向到index
,并将loggedin
设置为true
。