I know this question has been posted many times before, but I've been unable to find a good answer anyway, since the error doesn't exactly behave as it should.
You see, I have code similar to this:
<?php
include("banner.php");
include("menu.php");
print "<div class=\"wrapper\">";
if(true) header("Location:index.php");
else print "Hello World";
print "</div>";
include("footer.php");
?>
banner.php
looks like this:
<div id=banner><a href=index.php><img src=img/banner.png></a></div>
and menu.php
looks like this:
<ul class="menu">
<li class="dropdown">Menu
<ul>
<a href="test1.php?id=<?php print $id; ?>"><li>Item 1</li></a>
<a href="test2.php?"><li>Item </li></a>
<a href="test3.php"><li>Item 3</li></a>
<a href="test4.php?id=<?php print $id; ?>"><li>Item 4</li></a>
</ul>
</li>
</ul>
Note that there are a few PHP elements in menu.php
.
If I run the first piece of code, I get the error Warning: Cannot modify header information - headers already sent by (output started at /var/www/menu.php:10) in /var/www/test.php on line 5
. Line 10 in menu.php
is the last line. If I remove the menu completely from the code, and leave banner.php
, the code works fine. I find this confusing, since banner.php
does too provide output, as does the print "<div class=\"wrapper\">";
line right after the inclusion of the menu.
My question is simply this: Why does menu.php
trigger the error, while banner.php
doesn't?