|
Posted by J.O. Aho on 12/10/06 16:58
ulyx wrote:
> Cannot send session cookie - headers already sent by
>
> How to avoid this and why is this happening ?
You can't have any output before you use header()
examples:
--- file.php ---
<?PHP
/* This won't work, there is a empty row in the beginning of the file*/
header();
?>
--- eof ---
--- file.php ---
<?PHP
/* this won't work as there is output before the header() is used */
echo "something";
header();
?>
--- eof ---
--- file2.php ---
<PHP
function echo2() { echo "hello"; }
?>
--- eof ---
--- file1.php ---
<?PHP
/* This won't work as there is an empty row in the end of the include file */
include "file2.php";
header();
echo2();
?>
--- eof --
I hope you see the pattern, no output before header(), not any kind. You can
in some cases use output buffer to prevent output inside php to be sent before
the header, but don't affect whitespaces before/after php.
//Aho
Navigation:
[Reply to this message]
|