php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19673 Only last cookie of multiple setcookies is set.
Submitted: 2002-09-30 08:09 UTC Modified: 2002-09-30 09:43 UTC
From: Tawerner at web dot de Assigned:
Status: Closed Package: HTTP related
PHP Version: 4.2.2 OS: Linux 2.2.17 (Debian potato)
Private report: No CVE-ID: None
 [2002-09-30 08:09 UTC] Tawerner at web dot de
When setting multiple cookies in a script, only the last cookie remains. I tested it by:
  setcookie("one", "1");
  setcookie("two", "2");
  setcookie("three", "3");
Then I fetched the script via telnet to see the headers, and only one header was set:
  Set-Cookie: three=3
I tracked it down to ext/standard/head.c, end of the php_setcookie-funkction.
There, sapi_add_header gets executed. sapi_add_header is a macro to sapi_add_header_ex with the replace-bit SET!
That means, every cookie gets overwritten by its predecessor. In fact, only the last cookie remains.
I fixed it by exchanging the line
  return sapi_add_header(cookie, strlen(cookie), 0);
with
  return sapi_add_header_ex(cookie, strlin(cookie), 0, 0 TSRMLS_CC);
After compiling the patched PHP, setting multiple cookies succeedes.
Is that a bug in PHP or was it written on purpose, that only one cookie can be set?
I could have changed the macro in main/SAPI.h, but the macro is used in ext/zlib/zlib.c and ext/session/session.c and I didn't want to confuse them.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-30 09:43 UTC] sander@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 15:01:30 2024 UTC