I’ve been working on this project for three months (on Windows with PHP 5.4.12) and yesterday I finally decided it was ready to be uploaded.
My hosting server runs PHP 5.3.28 on Linux and as soon as I put all the files onto the website it does not work at all. The main trouble is related to the header
function, that is called as soon as the user inputs a valid username and password combination.
(I know that there are plenty of posts about this kind of issue but I could not take advantage of them so far).
Here is the code:
<?php
function login() {
//// Getting employee number
if (empty($_POST['field'])) {
$err[] = "missing field!";
} else {
$field = mysqli_real_escape_string($dbc, trim($_POST['field']));
}
//// same thing for the password
//// If there are no errors go with the query
if (empty($err)) {
go with the query and get the results
$count = mysqli_stmt_num_rows($stmt); // there must be 1 and only 1 user
if ($count == 1) {
session_start();
header("location: /members/home.php"); * * * * * * * * * * * * * * * * * * * * * * *
} else {
echo 'User not found!';
mysqli_stmt_close($stmt);
mysqli_close($dbc);
}
}
} else {
show the errors
}
Please do not mind the mismatching parentheses, I’ve brutally shortened the code. I require this file in the index.php
page with require
function and the form action is set to ""
).
I’ve read that there can be no output whatsoever before the header function, but I would not know how to put it differently in order not to cause the "header already sent..."
error. I realized too late that it all worked locally because I had ob enabled. Now the hosting company has enabled the ob for me but it still does not work.
Is there any way to make it work without a major recoding?