The following code, for some odd reason, works without error when the condition is true. I would like to know why, contrary to the expected error, it works.
include('includes/header.html');
echo "<div class = 'col-sm-6'>";
if (!ISADMIN && !(isset($_SESSION['id']) && isset($_GET['id']) && $_SESSION['id'] == $_GET['id'])) {
@require('includes/login_functions.inc.php');
redirect_user(''); // Redirects successfully
}
The function above, redirect_user()
, is in an includes file, and I call the function at the top of the most of my PHP files. Mainly, the function calls
header("Location: $url")
where $url is a local function scope variable.
The headers have already been sent, and HTML has already been both dynamically through PHP and statically through HTML printed to the page. However, as per the conditional, the user is still redirected if the conditional returns true. The reason this is a problem is when I try to reproduce it in a new file, I get the error I expect,
Warning: Cannot modify header information - headers already sent by (output started at
Additionally, I get this error as expected without the conditional, just calling redirect_user()
.
The includes
directory is located on the repository's GitHub. The page on the live site is http://www.bforborum.com/test
Edit
I have found that output_buffering was on, and I turned it off to no avail. With this set to 0, everything redirects whether or not headers are sent.