some php functions send http headers, due to http protocol requirements. for example: cookie/session functions or header("Location: ...").
in addition to that, whenever your script generates "textual" (html) output of any kind, php automatically sends an html page http header.
therefore, if you want your script to send more than one header while running, be sure to send the html header last. this means: session/cookie headers or redirection using header("Location: a_script.php") must come before any output is generated by your script.
right:
<?
if($blah)
{
header("Location: otherpage.php");
exit;
}
else
{
setcookie(...);
}
?>
<html>
<body>
bla bla bla
</body>
</html>
wrong:
<html>
<body>
<?
if($blah)
{
header("Location: otherpage.php");
exit;
}
else
{
setcookie(...);
}
?>
bla bla bla
</body>
</html>
note that blank lines or spaces also generate textual output!
an example pitfall:
<?
// my script blah blah
?>
<?
setcookie(...);
?>
<html>
<body>
...
mind the blank line before <? setcookie(); ! it will generate an html header - causing an error when reaching setcookie.
-> eliminate line breaks and/or spaces before functions which use cookies (or send other types of headers). if you're not sure whether a function sends headers, consult the php.net reference.
the error message is very helpful:
sent by (output started at /usr/local/apache/.../:2)
this means, your script sends an html header (= textual output: blank lines? spaces?) in line 2! check there!
hope this helps!