I am writing a code to connect to mysql and retrieve login info. I use connect.php to hold sensitive data which I get using require_once in login.php:
<?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'])) {
?>
With above, the db connection goes fine, but the header commands are not executed. If I remove require_once in login.php and I add directly the content of connect.php, so to have
$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 */
the header command is correctly processed and the redirection works successfully.
header and require_once are not compatible? or am I missing something else?
Thank you for your support