标头位置 PHP 不重定向页面


header location php not redirecting page

我在 PHP 的登录脚本中有以下代码。当我输入登录所需的电子邮件和密码时,页面会刷新,而不是将我重定向到page.php。最初需要从不同表中选择数据的代码,例如等级。如果查询字符串更改回以前的表名,则代码有效。现在我设置了一个不同的表,并认为更改查询中的表名称应该可以完成这项工作,但事实并非如此。请帮忙。

  <?php
include ('database_connection.php');
if (isset($_POST['formsubmitted'])) {
    // Initialize a session:
    session_start();
    $error = array(); //this aaray will store all error messages
    if (empty($_POST['e-mail'])) {//if the email supplied is empty 
        $error[] = 'You forgot to enter  your Email ';
    } else {
        if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9'._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9'._-]+)+$/", $_POST['e-mail'])) {
            $Email = $_POST['e-mail'];
        } else {
            $error[] = 'Your Email Address is invalid  ';
        }
    }
    if (empty($_POST['Password'])) {
        $error[] = 'Please Enter Your Password ';
    } else {
        $Password = $_POST['Password'];
    }
    if (empty($error)) {//if the array is empty , it means no error found
        $query_check_credentials = "SELECT * FROM enroll WHERE (email='$Email' AND password='$Password')";
        $result_check_credentials = mysqli_query($dbc, $query_check_credentials);
        if (!$result_check_credentials) {//If the QUery Failed 
            echo 'Query Failed ';
        }
        if (@mysqli_num_rows($result_check_credentials) == 1) {//if Query is successfull  // A match was made.
            $_SESSION = mysqli_fetch_array($result_check_credentials, MYSQLI_ASSOC); //Assign the result of this query to SESSION Global Variable  
            header("Location:pageX.php");
            exit();
        } else {
            echo $email;
            echo $password;
            $msg_error = 'Either Email address or Password is Incorrect';
        }
    } else {
        echo '<div class="errormsgbox"> <ol>';
        foreach ($error as $key => $values) {
            echo '  <li>' . $values . '</li>';
        }
        echo '</ol></div>';
    }

    if (isset($msg_error)) {
        echo '<div class="warning">' . $msg_error . ' </div>';
    }
    /// var_dump($error);
} // End of the main Submit conditional.
?>

重定向不起作用,因为Location:标头的值必须是绝对 URI,即它必须以协议开头。 pageX.php是一个相对的URI,虽然有些浏览器会尽力猜测程序员想要什么,但其他浏览器只是坚持标准,正如你所说,不要重定向。

尝试这样的事情:

header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/pageX.php');

它会像魅力一样工作。