|
Posted by ZeldorBlat on 09/27/35 11:37
Fernando Rodríguez wrote:
> Hi,
>
> Whenever I run a script page, I get this error:
> Warning: Cannot modify header information - headers already sent by (output
> started at c:\proyectos\websites\test\index.php:9) in c:\proyectos\websites\test\index.php
> on line 11
>
> My code is:
>
> <?
> $cookieValue = 'abra cadabra, pedo de cabra';
> setcookie('aTestCookie', $cookieValue, time() + 3600);
> ?>
>
> Any ideas? O:-)
>
> Thanks
You get that error message because the headers have already been sent
and output has started. Specifically, you sent output on line 9 of
index.php. If you want to set HTTP headers (and setting a cookie
requires sending a header) you need to do it *before* you send any
other output to the browser -- even a single whitespace counts.
So, you have two options here:
1. Re-order the script so that you call setcookie() before you send any
output.
2. Use ob_start() and ob_flush() to buffer the output (see
<http://www.php.net/manual/en/ref.outcontrol.php> for more information).
Navigation:
[Reply to this message]
|