问题
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 elements...
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.
回答1:
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.
回答2:
You can find out where the headers were sent with:
if (headers_sent($file, $line)) {
echo "Headers were sent at file=$file, line=$line";
}
回答3:
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.
来源:https://stackoverflow.com/questions/6034750/can-saving-in-unicode-utf-8-including-bom-elements-break-my-header-location-on-m