似乎有一些我根本想不通的问题。
以下代码在我的本地环境中正常运行,但它在我的实时环境中无效。使用与我的本地环境完全相同的文件结构,所以我看不出这是问题所在。
这是我的文件结构,可以帮助任何人回答
Root folder Includes in root folder
有问题的文件是root中includes文件夹中的login.php
<?php
if(isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$username = mysqli_real_escape_string($connection, $username);
$password = mysqli_real_escape_string($connection, $password);
$query = "SELECT * FROM users WHERE username = '$username' ";
$select_user = mysqli_query($connection, $query);
if(!$select_user) {
die ("Query Failed ". mysqli_error($connection));
}
while($row = mysqli_fetch_array($select_user)) {
$db_id = $row['user_id'];
$db_usename = $row['username'];
$db_password = $row['user_password'];
$db_firstname = $row['user_firstname'];
$db_lastname = $row['user_lastname'];
$db_role = $row['user_role'];
}
if($username === $db_usename && $password === $db_password) {
$_SESSION['username'] = $db_usename;
$_SESSION['firstname'] = $db_firstname;
$_SESSION['lastname'] = $db_lastname;
$_SESSION['role'] = $db_role;
header("Location: ../admin");
} else {
header("Location: ../index.php");
}
}
?>
编辑:问题在另一个主题中回答。原来是白色空间
答案 0 :(得分:2)
也许您需要在ob_start
header
ob_start();
header('Location: ...');
或您的文件无法在您的服务器上访问,因为您的环境。
确保您的服务器可以访问文件../login.php