Re: Warning: Cannot add header information - headers already sent

From: Jedi121 (jedi121news_at_free.fr.Removethis)
Date: 03/08/04


Date: Mon, 08 Mar 2004 20:27:40 +0100

Phyzlo a écrit le 08/03/2004 :
> Hello,
Hi

> I've recently started learning PHP and have a question.
> I tried running below script which can be found at
> http://se2.php.net/manual/sv/function.setcookie.php
>
> but I keep getting this message on my browser, why?
Because you didn't read the doc about Cookies.
http://www.php.net/setcookie
You must NOT output anything before using setcookie()
You MUST reload the page to see the cookie set.

> -----
>
> <?
> echo "Setting cookie";
Delete this line and it'll run.
>
> $value = 'Test value';
>
> setcookie("TestCookie", $value);
> setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
> setcookie("TestCookie", $value, time()+3600, "/~rasmus/",
> ".example.com", 1);
>
> echo "Cookie Set!";
> ?>