簡體   English   中英

注冊后重定向不起作用

[英]redirect after registration is not working

我不明白為什么我的重定向不起作用? 我得到的只是一個空白頁面,其中的 url 與我嘗試重定向的地址相同。代碼來自我的注冊頁面,但是我刪除了一些代碼,以便在此處查看我的重定向。 除了重定向之外,其他一切都在工作。

  <?php

if($_SERVER["REQUEST_METHOD"] == "POST"){

 //removed bunch of code for clear overview for stackoverflow question
 // Prepare an insert statement

        $sql = "INSERT INTO users (username, password) VALUES (?, ?)";



        if($stmt = mysqli_prepare($link, $sql)){

            // Bind variables to the prepared statement as parameters

            mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);



            // Set parameters

            $param_username = $username;

            $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash



            // Attempt to execute the prepared statement

            if(mysqli_stmt_execute($stmt)){
              // Redirect to login page
            header("location: login.php");
            } else{

                echo "Something went wrong. Please try again later.";

            }

        }



        // Close statement

        mysqli_stmt_close($stmt);

    }



    // Close connection

    mysqli_close($link);

}

?>

如果您要訪問此頁面,我認為您的重定向可能會起作用。 你會得到一個空白頁,因為你的代碼以:

if($_SERVER["REQUEST_METHOD"] == "POST"){

您聲明您已刪除一些代碼。 如果您希望運行的代碼也在該代碼塊中並且它不是POST (這可能是GET ),則不會執行該代碼塊中的代碼。

您的示例中沒有表單標簽,但您也可以檢查是否使用method="POST"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM