|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5653 PIKE specific: with setcookie(), only the last cookie is written
Submitted: 2000-07-18 05:48 UTC Modified: 2002-06-18 18:46 UTC
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: schulte at delta7 dot de Assigned:
Status: Closed Package: Other web server
PHP Version: 4.0.5 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: schulte at delta7 dot de
New email:
PHP Version: OS:


 [2000-07-18 05:48 UTC] schulte at delta7 dot de
I'm using PHP4.0.1.pl2
i tried this example out of the PHP3-Manual (section setcookie)
--> i need to store more than on value in my script.
here is the code I used

setcookie ("cookie[three]", "cookiethree");
setcookie ("cookie[two]", "cookietwo");
setcookie ("cookie[one]", "cookieone");
 if (isset ($cookie)) {
     while (list ($name, $value) = each ($cookie)) {
            echo "$name == $value<br>\n";
so far no error occurs, but i can see only the last cookie this script wrote to by browser (netscape 4.6/4.7).
You can also try to write separate cookies , but only the last is accepted.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-18 06:14 UTC] hholzgra at cvs dot php dot net
sorry, i can't reproduce this with latest CVS
(and i have used multiple cookies before, 
so it should have worked for ages)

but take note that php3 sent cookies in revers 
order while php4 doesn't rearrange them

so with php3 you would get cookieone -two -three
while in php4 you get cookiethree -two -one
when using your sample code

 [2000-07-18 11:34 UTC] hholzgra at cvs dot php dot net
> You can see the result of this script at 
> if you like, I would add an phpinfo() at the end of this script.

looks like this is a problem related to roxen sapi?
 [2000-08-15 10:56 UTC]
Is this problem still existent?
 [2000-08-15 15:57 UTC]
user feedback:
Yes, I tried the latest snapshot from 15.Aug.2000.
But the Result is still the same.
Maybe you can give me a hint how to give a trace or debug a
certain part of php4

 [2000-08-15 16:04 UTC]
seems to be another error related to
roxen sapi and cookies ...

PS: bug report form should have a sapi
    input field
 [2000-08-17 16:19 UTC]
This is not a session-related issue. Reclassifying.
 [2000-09-14 16:33 UTC] schulte at delta7 dot de
This behaviour is still visible in PHP 4.0.2 with Roxen (pike 7.0.58).

 [2000-10-30 09:40 UTC]
 [2001-05-06 12:31 UTC] schulte at delta7 dot de
This bug is still present in 4.0.5.
 [2001-05-06 16:45 UTC]
is this still the case with the latest 4.0.5 release?
 [2001-07-23 19:25 UTC]
this is probably a browser related problem (the browser only
lets you set noe cookie per site.)  Does anyone else agree
or has somebody actually reproduced this one?
 [2001-07-23 19:26 UTC]
i meant to say "only lets you set ONE"
 [2001-07-24 02:01 UTC] schulte at delta7 dot de
This is not a browser-specific bug. It's only pike-specifc (roxen) .

I spent some time to undaerstand the roxen-sapi-code, but at last I'm not able to fix it.
This 'bug' is already mentioned in the README....

So this 'bug' should be listed in 'missing features' or 'todo's' but not maybe not in 'bugs'

 [2001-07-24 09:02 UTC]
this could be because your server is only sending one cookie to 

Try creating a script like the one below...
setcookie ("cookie1","helloworld");


go down to the section about the "HTTP Headers Information"
then go to the "HTTP Response Headers."  Either post this
information here, or give us the address to that page.
 [2001-07-24 12:23 UTC] schulte at delta7 dot de
OK here is the result...

Variable Value 
PHP_SELF  =  /test.php 
HTTP_COOKIE_VARS["cookie3"] = phprocks  

if you don't believe you can try at
The real problem is in source-file src/sapi/roxen/roxen.c about line 298 (in ver 4.0.6 of PHP)...
this function (pike):
mapping_string_insert(REQUEST_DATA, ind, &mappie);
does not append headers of the same type (here cookies).
this means: old cookies are deleted and replaced with the last one you set.

The Problen is _not_ on the side of the webserver. I found out (and may proove) that the roxen-php-module will recieve more than only one cookie.... if you like, i would make some php-scripts that will show you...


 [2001-08-14 20:08 UTC]
feedback -> open
 [2001-08-16 12:55 UTC]
[2001-08-16 12:24:36]

There is small problem in Roxen's SAPI, which arises when duplicate headers are sent out.
While playing with some PHP apps with Roxen, I found that regardless how many cookies are
set in PHP code, only one is sent to the browser.

Investigation shows that Roxen's SAPI uses Pike's type "mapping" to send
headers, which (of course) doesn't allow duplicate headers (in my case
"Set-Cookie") to be sent, i.e. only last one is sent, since subsequesnt calls to
set header with the same name will replace previous.

Proposed solution: use array instead of mapping. It will require changes in Roxen module
as well, of course, but this should not be difficult.

 [2002-01-11 16:45 UTC]
Can this be reproduced with the PHP 4.1.1, and perhaps the latest roxen/pike?
 [2002-02-02 06:40 UTC]
No feedback was provided for this bug, so it is being suspended.
If you are able to provide the information that was requested,
please do so and change the status of the bug back to "Open".
 [2002-05-29 14:20 UTC] bouke_haarsma at hotmail dot com
i'm using apache 2.0.36 and php 4.2.1, and since I'm using apache the cookie problems appeared.
 [2002-06-10 21:27 UTC] rick at ozrock dot com
I also am using Apache 2 and PHP 4.2.1 WIN32 (with the apache2 API).
 [2002-06-10 21:29 UTC] rick at ozrock dot com
I also am using Apache 2 and PHP 4.2.1 WIN32 (with the apache2 API)....
and only the last cookie is set.
 [2002-06-11 14:19 UTC] koxta at tha dot one dot pl
I am also using Apache 2.0.36 and PHP 4.2.1 on Linux Mandrake OS. This setcookie() problem occures.
 [2002-06-11 14:25 UTC]
The setcookie() bug on Apache 2 has been fixed in CVS and will be in the next release. (4.3.0 probably, scheduled for august this year, if you can't wait that long, use
 [2003-12-11 12:26 UTC] j dot engel at defacto dot com
I am still getting the problem.

Only one of the cookies you try and write are sent. I've tried using the header, and set-cookie functions. I've installed the latest snap version. 4.3.5-dev of php.

I'm using php 4.3.5-dev on win32 sp4, iis5, isapi module.

I've run into this problem before, and i had to revert to apache. I don't want to have to do that again.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 12:01:30 2024 UTC