By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,971 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,971 IT Pros & Developers. It's quick & easy.

Warning: Cannot add header information - headers already sent

P: n/a
Hello,

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?

Warning: Cannot add header information - headers already sent by
(output started at /var/www/cookietest.php:2) in
/var/www/cookietest.php on line 6

Warning: Cannot add header information - headers already sent by
(output started at /var/www/cookietest.php:2) in
/var/www/cookietest.php on line 7

Warning: Cannot add header information - headers already sent by
(output started at /var/www/cookietest.php:2) in
/var/www/cookietest.php on line 8

-----

<?
echo "Setting cookie";

$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!";
?>
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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!";
?>

Jul 17 '05 #2

P: n/a
You're right thanks!

//Regards
Jedi121 <je*********@free.fr.Removethis> wrote in message news:<me********************************@free.fr.R emovethis>...
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!";
?>

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.