Warning: Cannot add header information - headers already sent

From: Phyzlo (phyzlo_at_yahoo.com)
Date: 03/08/04


Date: 8 Mar 2004 11:16:53 -0800

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!";
?>



Relevant Pages

  • [UNIX] Malicious PHP Source Injection in phpBB (install.php)
    ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... Warning: Cannot add header information - headers already sent by (output ... int main ...
    (Securiteam)
  • IMP 2.2.7 pen-test
    ... I sent an email yersterday regarding pen-testing a linux system. ... Warning: Cannot add header information - headers already sent by (output ...
    (Pen-Test)
  • Debian with Apache, php4, mysql and phpmyadmin
    ... i've installed phpmyadmin today on my server. ... Warning: Cannot add header information - headers already sent by (output ...
    (Debian-User)
  • Porting M0n0wall WebGUI to freebsd 5.4 Stable
    ... Than i've download rootfs from m0n0 ... to porting webgui into freebsd box. ... Warning: Cannot add header information - headers already sent by (output ...
    (freebsd-questions)