tags:

views:

26

answers:

4

Hi, When creating cookie as follows <?php setcookie("TestCookie", $value, time()+3600 ?>

php shows warning like

Warning: Cannot modify header information - headers already sent by (output started at /var/www/test/demo/header.php:14)

How can we overcome this issue.

A: 
revaxarts
A: 

You can not set any HTTP headers (and cookie is set in such header) if you've already send any content to browser. Either move you setcookie before line 14 in header.php, or move header header creation after setting cookie (yes, I know it's same thing - that's the point)

Mchl
A: 

That is not directly Cookie related, but that you can not set any Header Informations (including cookies) after you made any Kind of Output (can include blank lines in the php file)

Hannes
A: 

If your script really is what you've shown here, then either:

  • the webserver is setup wih an auto-prepend which is creating output (even a single whitespace is enough)

  • or you've saved your file as utf-8 including a BOM marker - try saving as ASCII instead.

Since the error appears to be getting logged at line 14, then iether you've got an auto-prepend - or the code is not what you've shown here.

symcbean
SO sometimes makes me think that noone can read here.
Col. Shrapnel