Header函数正在重定向到index.php,而不是指定的文件(php)


Header function is redirecting to index.php instead of the specified file (PHP)

我目前正在将文件组织到适当的文件夹中,出现了一个问题。在更改代码以组织文件之前,一切都正常。现在,每当我尝试登录时,它都会重定向到"Staff/index.php",而不是重定向到"Staff/Staff.php"。

代码如下:

<?php
    session_start();
    include("connectdb.php");
    //if the form has been submitted
    if (isset($_POST['submitted'])){
    //get the information out of get or post depending on your form
        $username = $_POST['username'];
        $password = $_POST['password'];
        global $db;
        //sanitise the inputs!
        $safe_username = $db->quote($username);
        //run a query to get the user associated with that username
        $query = "select * from user where username = $safe_username";
        $result = $db->query($query);
        $firstrow = $result->fetch(); //get the first row
        if (!empty($firstrow)) {
            //check the passwords, if correct add the session info and redirect
            $hashed_password = md5($password);
            if ($firstrow['password'] == $hashed_password){
                $_SESSION['id'] = $firstrow['userID'];
                $_SESSION['username'] = $firstrow['username'];
                $_SESSION['fname'] = $firstrow['first_name'];
                $_SESSION['lname'] = $firstrow['last_name'];
                $_SESSION['staff'] = $firstrow['staff'];
                if($firstrow['staff'] == 1) {
                    header("Location:Staff/staff.php");
                    exit();
                } else {
                    //echo "Success!";
                    header("Location:Customer/customer.php");
                    exit();
                }
            } else {
                echo "<h1>Error logging in, password does not match</h1>";
            }
        } else {
            //else display an  error
            echo "<h1>Error logging in, Username not found</h1>";
        }
    }
?>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="CSS/theme.css">
    </head>
    <body>
        <h1 class="register-title">Aston Animal Sanctuary</h1>
        <div class="register">
            <!--<form method="link" action="staff.php">
                <input type="submit" value="Staff Login">
            </form>-->
            <form action="index.php" method="post">
                <input type="text" class="register-input" name="username" placeholder="Username">
                <input type="password" class="register-input" name="password" placeholder="Password">
                <input type="submit" value="Login" class="register-button">
                <input type="hidden" name="submitted" value="TRUE" /> 
            </form>
            <form method="link" action="register.php">
                <input class="register-button" type="submit" name="register" value="Register">
            </form>
        <div>
        <!--<a href="test1.php" class="button">Test</a>-->
    </body>
</html>
<?php include('View/footer.html'); ?>

收割台有问题吗?


编辑

同样的事情也发生在我的注销文件上。它重定向到"Staff/loog.php"而不是".."/logout.php。在我开始组织文件之前,它就已经工作了。

注销的代码.php:

<?php
session_start(); //get the previous session info
session_destroy(); //destroy it
header("Location: ../index.php"); //redirect back to the start
?>

您尝试过吗:

header("Location: ./staff/staff.php");

和:

header("Location: ./customer/customer.php");