如果REQUIRED_ONCE存在,HEADER命令将不起作用



我正在编写一段代码来连接到mysql并检索登录信息。我使用connect.php来保存敏感数据,这些数据是我在login.php中使用require_sonce获得的:

<?php
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";
?> 
<?php
$checkMail= $_POST["email"];
$checkPwd= $_POST["password"];
$registration_status='Active';
require_once ('connect.php'); 
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed, please retry later: " . $conn->connect_error);
}
$sql = "SELECT email, password, registration_type, registration_status, emailupdate FROM registration where  email='".$checkMail."'";
$result = $conn->query($sql);
if ($result->num_rows == 1) {
while($row = $result->fetch_assoc()) {
if ($row['registration_status'] == "Deactive") {
session_start();    
$_SESSION['error'] = "<b>This user name is deactivated. <br> Please create a new account.</b><span>";
header("Location: http://www.xxxxxxx//registration.php"); /* Redirect browser */ 
}
elseif (password_verify($checkPwd, $row['password'])) {
?> 

在上面的情况下,数据库连接正常,但头命令不会执行。如果我在login.php中删除require_one,并直接添加connect.php的内容,那么就有了

$checkMail= $_POST["email"];
$checkPwd= $_POST["password"];
$registration_status='Active';
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = "xxx"; 
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed, please retry later: " . $conn->connect_error);
}
$sql = "SELECT email, password, registration_type, registration_status, emailupdate FROM registration where  email='".$checkMail."'";
$result = $conn->query($sql);
if ($result->num_rows == 1) {
while($row = $result->fetch_assoc()) {
if ($row['registration_status'] == "Deactive") {
session_start();    
$_SESSION['error'] = "<b>This user name is deactivated. <br> Please create a new account.</b><span>";
header("Location: http://www.xxxxxxx/registration.php"); /* Redirect browser */ 

header命令得到正确处理,重定向工作成功。

header和require_one不兼容?还是我错过了什么?

感谢您对的支持

空白

页眉无法工作,因为您正在打印空白。请删除此关闭/打开标记组合,然后重试。

最新更新