Can saving in Unicode UTF 8 including BOM elements break my header location on my site?
I use header Location across my site and there was no problem. I then added a language (French) and had to save my files in Unicode UTF 8 including BOM ele开发者_如何学运维ments...
Now my header location doesn't work anymore...the weird part being that there is no error message displayed...
So I updated my function to display a self made error message...see below
function redirect_to( $location = 'index.php'){
// code reached, error_reporting test
#flush();
if (headers_sent()) {
echo 'Debug: would send location header ', $location, $unsetVariableTriggeringWarning;
die('cannot send location header (anymore)');
}
else {
header('Location: '.$_SESSION['base_url'].$location);
die();
}
}
And I do get the error message now:
Debug: would send location header access.php?redirecto=accountcannot send location header (anymore)
But nothing has been printed out yet, no HTML, no PHP, no nothing. So my best guess was when I converted to Unicode utf8, there must of been something that happened. So I switched back, but still, the error persists...
Any help, much appreciated.
The PHP engine does not consume the BOM that would be before the <?php
in the script, so it will be sent out as usual. Remove the BOM.
You can find out where the headers were sent with:
if (headers_sent($file, $line)) {
echo "Headers were sent at file=$file, line=$line";
}
Make sure you haven't accidentally injected whitespace before your first <?php
opening tag. Whitespace also counts as output so it may make you unable to send headers.
精彩评论