Header函数正在重定向到index.php,而不是指定的文件(php)
我目前正在将我的文件整理到适当的文件夹中,出现了一个问题。在更改代码以组织文件之前,一切正常。现在,每当我尝试登录时,它都会重定向到“Staff/index.php”,而不是重定向到“Staff/Staff.php” 代码如下:Header函数正在重定向到index.php,而不是指定的文件(php),php,html,header,Php,Html,Header,我目前正在将我的文件整理到适当的文件夹中,出现了一个问题。在更改代码以组织文件之前,一切正常。现在,每当我尝试登录时,它都会重定向到“Staff/index.php”,而不是重定向到“Staff/Staff.php” 代码如下: <?php session_start(); include("connectdb.php"); //if the form has been submitted if (isset($_POST['submitted'])){
<?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/logout.php”,而不是“../logout.php”。在我开始整理文件之前,它起了作用 logout.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");
以及:
你能发布
staff.php
吗?除此之外,你在.htaccess
文件中有任何重定向或重写规则吗?我没有.htaccess文件是你在表单中给出的index.php文件,如果有,可能只是将action留空,因为这可能会导致它。
header("Location: ./customer/customer.php");