View Full Version : cookie error

02-07-2003, 09:18 AM
just tried every single variation of setcookie I can think of, and it doesn't work. Gives me the following error:

Warning: Cannot add header information - headers already sent by (output started at /home/location/testing.phtml:9) in /home/location/testing.phtml on line 12

$time = time() + 30;
$value = session_id();

setcookie("yummycookie", $value , $time);

Tried every single variation I could think of, and I still keep getting the same error.

any suggestions??


02-07-2003, 09:54 AM
Setcookie must be the first thing in a php file. You have some output before it (line 9) and this is causing the problem.

Taken from the php web site:

Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. If output exists prior to calling this function, setcookie() will fail and return FALSE.

02-07-2003, 10:01 AM
Gotcha, didn't know what they meant by headers when they mentioned it.