验证密码但无法正常工作时,PHP没有错误

时间:2019-05-19 13:23:36

标签: php mysql

我正在为我的学校项目创建一个登录系统,并且在验证密码时卡住了。它没有给出任何错误,但是没有用。

我试图修改代码结构,但无济于事。

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

0 个答案:

没有答案