为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
森栏 2021-05-04 17:25:40
我会简短明了,因为无论发布什么内容,我似乎都被禁止了。我在这里发现了类似的问题,但是所有建议都与我的代码无关。登录成功重定向到新页面后,我只需要帮助即可。 $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";?>
查看完整描述

2 回答

?
POPMUISE

TA贡献1765条经验 获得超5个赞

我只是忘了标题后面的分号。


$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();

    }


查看完整回答
反对 回复 2021-05-28
?
偶然的你

TA贡献1841条经验 获得超3个赞

可能会有一些变化,如下所示:


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.

    }

}


查看完整回答
反对 回复 2021-05-28
  • 2 回答
  • 0 关注
  • 210 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信