Leave a comment

Causes for php Warning: Cannot modify header information – headers already sent

UntitledFirst : Echo before header

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

Solution:

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

Second : New-line characters or spaces before <?php

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

Solution:

Remove everything before <?php

Third : Header Location in mixed php/HTML

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

Solution:

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

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

<?php
...
?>

   ... 
...

Solution:

Remove everything after ?> in the php include file

Leave a comment