|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19063 Can't set any cookie. Received error warning about header.
Submitted: 2002-08-23 03:38 UTC Modified: 2002-08-23 11:40 UTC
From: h_tr_dung at hotmail dot com Assigned:
Status: Not a bug Package: HTTP related
PHP Version: 4.2.2 OS: WinXP Pro. and FreeBSD 4.6
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: h_tr_dung at hotmail dot com
New email:
PHP Version: OS:


 [2002-08-23 03:38 UTC] h_tr_dung at hotmail dot com
I have tested the "baking" file (please see below) in two machines and received the same error:

Warning: Cannot add header information - headers already sent by (output started at ...\setcookie.php:1) in ...\setcookie.php on line 2

The first system used: WinXP Pro., IIS (built-in with WinXP).

The second system used: FreeBSD 4.6, Apache/1.3.26.

The "baking" file's content:
setcookie ("Chip_Name",$Chip);
echo "<BODY OnLoad=\" location='".$forwarding."' \">";

The test file's content:
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
echo $Chip_Name;
<a href="setcookie.php?Chip=Chocolate&forwarding=<?php echo $PHP_SELF ?>">Test SetCookie() Function</a>

Is it a bug?!? Or there is something wrong with my code?!? I couldn't even "bake" any cookie because some headers were sent first, but how could? 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-23 07:15 UTC]
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit

Thank you for your interest in PHP.
 [2002-08-23 10:11 UTC] h_tr_dung at hotmail dot com
My code has nothing wrong (as you can see)! This was a bug and I reported it. However, I guess I should have done it with an aggresive tone to get more attention from you.

 [2002-08-23 10:32 UTC]
It is very very unlikely that there is a PHP bug here.  You probably have something before the opening <?php tag in the file that sets the cookie.  Put up a .phps or a .zip file somewhere with the actual files in question so we can have a look.  And when we do explain your mistake to you, you can apologize nicely to sniper.
 [2002-08-23 10:50 UTC] h_tr_dung at hotmail dot com
Thanks rasmus,

Below are the links:

Test file:

SetCookie file:

Source codes in ZIP

Domain vietecon running FreeBSD 4.6, Apache/1.3.26 (as I described).

P.S. Sorry to sniper if my tone was harsh to you.
 [2002-08-23 10:57 UTC]
And "od -c" of your setcookie.php file reveals, as I predicted, that you have crap before your <?php tag.

0000000   ?   ?   ?   <   ?   p   h   p  \r  \n   s   e   t   c   o   o
0000020   k   i   e       (   "   C   h   i   p   _   N   a   m   e   "
0000040   ,   $   C   h   i   p   )   ;  \r  \n   e   c   h   o       "
0000060   <   B   O   D   Y       O   n   L   o   a   d   =   \   "    
0000100   l   o   c   a   t   i   o   n   =   '   "   .   $   f   o   r
0000120   w   a   r   d   i   n   g   .   "   '       \   "   >   "   ;
0000140  \r  \n   ?   >

Use a non-bogus text editor and it should work fine.
 [2002-08-23 11:40 UTC] h_tr_dung at hotmail dot com
Thank you!!!

BTW, attention to anyone who uses Dreamweaver MX to encode your document in Unicode (utf-8). You will experience the same problem. I changed the encoding to Western (Latin1) and it worked just fine.

I guess the 'crap' you have mentioned is some code reporting that the document was encode in Unicode (utf-8).
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Oct 04 07:04:13 2022 UTC