Bug #16626 Updated: Only last cookie set
| From: | cabel-s at panic dot com | Date: | Wed, 24 Apr 2002 17:54:39 +0000 |
| Subject: | Bug #16626 Updated: Only last cookie set | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-5856@lists.php.net to get a copy of this message | ||
ID: 16626
Updated by: cabel-s@panic.com
Reported By: svein.olav@bjerkeset.com
Status: Open
Bug Type: Apache2 related
Operating System: RedHat 7.2 (kernel 2.4.18) i386
PHP Version: 4.2.0
New Comment:
Now I know what "don't use this on a production server" means. :)
Strangely, this bug also seems to affect header().
As a result of this bug, we replaced setcookie() with our own routine
to write out cookies via header().
However, still, only one cookie (the last one) is being printed in the
HTTP response headers (when I sniff the packets being sent).
It's very strange...
Here's the code we used to replace setcookie().
function send_htCookie() {
$vars=array('varname','varval','expire','path','domain','secure');
for ($i=0;$i<func_num_args();$i++) {
${$vars[$i]}=func_get_arg($i);
}
if (!$varname) { return false; }
$COOKIE = "Set-Cookie: $varname=$varval";
if (isset($expire)) { $COOKIE .= "; EXPIRES=$expire";}
if (isset($domain)) { $COOKIE .= "; DOMAIN=$domain"; }
if (isset($path)) { $COOKIE .= "; PATH=$path"; }
if (isset($secure) && $secure>0) { $COOKIE .= "; SECURE"; }
header($COOKIE);
return true;
}
Can anyone confirm that this, too, doesn't work for them?
I'll do more testing in the meantime...
Previous Comments:
------------------------------------------------------------------------
[2002-04-23 09:56:19] cpr@hal-9000.net
I get the same problem on FreeBSD 4.5 with Apache 2.
------------------------------------------------------------------------
[2002-04-23 04:22:00] svein.olav@bjerkeset.com
Bug reproduced with 4.2.0
------------------------------------------------------------------------
[2002-04-16 16:37:10] svein.olav@bjerkeset.com
Same problem as BUG# 16631.
(Problem also with RC2 and RC3 of 4.2.0)
------------------------------------------------------------------------
[2002-04-15 17:19:12] svein.olav@bjerkeset.com
With Apache 2.0.35 and PHP 4.2.0RC4, only the last cookie
seems to get set.
Here is the PHP source I used for testing:
<?php
setcookie ('first_name', 'Svein', 0, '/');
setcookie ('last_name', 'Olav', 0, '/');
echo "<html><head></head><body>" .
"<h1>Cookie test page</h1>\n";
while (list ($var,$val) = each ($HTTP_COOKIE_VARS)) {
echo "Set-Cookie: $var=$val <br>\n";
}
echo "</body></html>";
?>
This script can be tested via the following URL:
https://bjerkeset.dns2go.com/php/cookie.php
PHP was configured like this:
./configure \
--prefix=/opt/php \
--with-mysql=/opt/mysql \
--with-config-file-path=/etc/opt/apache2 \
--enable-track-vars \
--enable-force-cgi-redirect \
--with-gettext \
--with-apxs2=/opt/apache2/bin/apxs
Svein Olav Bjerkeset
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=16626&edit=1