php Warning:

Cannot modify header information - headers already sent

Echo before header

<?php
echo "hello world"
...
header('Location: http://...');
?>

 

Solution:

RemoveRemove the echo before header
Use ob_start(); and ob_end_flush(); for buffered output

 


 

New-line characters or spaces before <?php

       <?php
... header('Location: http://...');
?>

 

Solution:

Remove everything before <?php

 


 

BOM (Byte-Order-Mark ) in utf-8 encoded php files

If you have edited the php file with a text editor like notepad and saved it, then you might get the error message above. The reason is the utf-8 BOM (Byte-Order-Mark) added by some text editors, like e.g. notepad. The php script should not have a BOM, since the BOM contains chars, which are "sent" before the header function.

<?php
...
header('Location: http://...');
?>

 

Solution:

Change the file encoding to "without BOM" (e.g. using notepad++) or remove the BOM before <?php using a HEX editor

Header Location in mixed php/HTML

<html>
...
<body>
...
<?php header('Location: http://...'); >
...
</body>
</html>

 

Sorry, you cannot use header-location here, because the header and the HTML code have already been sent!

 


 

Empty lines, chars or spaces after ?> when using an php include file

<?php
...
?>

   ...
...

 

Solution:

Remove everything after ?> in the php include file

Disclaimer: The information on this page is provided "as is" without warranty of any kind. Further, Arclab Software OHG does not warrant, guarantee, or make any representations regarding the use, or the results of use, in terms of correctness, accuracy, reliability, currentness, or otherwise. See: License Agreement