Reply to Re: Warning: session_start() [function.session-start]:

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация