php函数header()不起作用

时间:2016-03-29 22:33:29

标签: php

页面刷新而不是转到index.php。即使我在代码中的任何位置移动它,标题函数似乎也无法正常工作。有谁知道为什么会这样?会感谢你的帮助!

<?php

if (isset($_POST['btnLogin'])) {

    $Email = $_POST['email'];
    $Password = $_POST['password'];

    $Email = mysqli_real_escape_string($connection, $Email);
    $Password = mysqli_real_escape_string($connection,$Password);

    $query ="SELECT * FROM users WHERE Email = '{$Email}'";
    $select_customer_query = mysqli_query($connection, $query);

    if(!select_customer_query) {
        die("QUERY FAILED". mysqli_error($connection));
    }

    while($row = mysqli_fetch_array($select_customer_query)) {

        $stored_Email = $row['Email'];
        $stored_Password = $row['Password'];
        $User_ID = $row['User_ID'];
        $string ="Logged in as";
        $logoutlink = '/ <a href="resources/includes/back/logout.php">Logout</a>';
        $Firstname_db = $row['First_Name'];
        $Lastname_db = $row['Last_Name'];
        $role_db = $row['Role'];
    } 

    if (password_verify($Password,$stored_Password) ) {

        $_SESSION['FirstName'] = $Firstname_db;
        $_SESSION['LastName'] = $Lastname_db;
        $_SESSION['Email'] = $stored_Email;
        $_SESSION['string'] = $string;
        $_SESSION['logoutlink'] = $logoutlink;
        $_SESSION['User_ID'] = $User_ID;
        $_SESSION['Role'] = $role_db;

        echo '<div class="alert alert-success alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button> Your Email and Password was correct.  Click this link to go to <a href="index.php"> Home </a> </div> ';

    } else {

        if ($Email == $stored_Email && $Password !== $stored_Password) {

            echo '<div class="alert alert-danger alert-dismissible" role="alert">
              <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <strong>Warning!</strong> Your Password Was Incorrect. Please Try Again. </div> ';

        }
    }  

    if ($Email !== $stored_Email && $Password !== $stored_Password) {

        echo '<div class="alert alert-danger alert-dismissible" role="alert">
              <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <strong>Warning!</strong> Your Email or Password Was Incorrect. Please Try Again. </div> ';

    } 

    header('Location: index.php');

}
?>

0 个答案:

没有答案