猿问

使用php登录成功后如何重定向到新页面

我会简短明了,因为无论发布什么内容,我似乎都被禁止了。我在这里发现了类似的问题,但是所有建议都与我的代码无关。


登录成功重定向到新页面后,我只需要帮助即可。


 $username = $_POST["username"]; 


    $conn = mysqli_connect($host, $user, $pass, $db);



    $query = "SELECT * FROM user WHERE username = '" .$username.  "'";

    $result = mysqli_query($conn,$query);


    while ($row = mysqli_fetch_assoc($result)){

        echo "Password Entered: " . $_POST["password"];

        echo "Correct Pasword: " . $row['password'];


        // See if the password is correct

        if ($_POST["password"] === $row['password'])

            echo "Logon Successful!";



        else {

            echo "Logon Failed!";

        }

    }

     if (!mysqli_fetch_assoc($result))

        echo "Invalid Username";

?>


森栏
浏览 211回答 2
2回答

POPMUISE

我只是忘了标题后面的分号。$query = "SELECT * FROM user WHERE username = '" .$username.  "'";$result = mysqli_query($conn,$query);while ($row = mysqli_fetch_assoc($result)){    // See if the password is correct    if  ($_POST["password"] === $row['password']){        echo "Logon Successful!";        header("Location: index.php");         exit();    }

偶然的你

可能会有一些变化,如下所示:login.php$username = $_POST["username"]; $password = $_POST["password"];$conn = mysqli_connect($host, $user, $pass, $db);$query = "SELECT * FROM user WHERE username = '" . $username .  "'";$result = mysqli_query($conn,$query);while ($row = mysqli_fetch_assoc($result)){    // See if the password is correct    if ($password === $row['password']){        header('location: login_successful.php');    }else {        // you can hide the message at QueryString via SESSION or COOKIE        header('location: login_form.php?message=FAIL_MESSAGE');  //you can detect and show login status message.    }}
随时随地看视频慕课网APP
我要回答