Page 1 of 1

Problem Setting Cookies

Posted: Sat Jun 01, 2002 5:28 am
by James Pelow
When I try to set cookies only the last one in a series of three actually sets. The other two are stuck at the top of the HTTP headers on their own with no Set-Cookie directive. This has only happened since (1) My Host started using Apache 2 (2) My host has auto start session on (3) My host updated to 4.2.1.

My script is fully compatible with 4.2.x and works on my localhost box running Mac OS X/Darwin Apache 1.3.23, PHP 4.2.0. I've played around with my script and I am nearly confident that it is a server issue. Has anyone else experienced such problems?

-James :(

Problem Resolved

Posted: Sun Jun 02, 2002 5:50 am
by James Pelow
Documented bug in php 4.2.0/4.2.1 causes condition where only last cookie is set when using in conjunction with Apache 2.

Example:

After running this code:

Code: Select all

$lifetime = time() + 3600 * 24 * 365;
setcookie ("cookiea", "loo", $lifetime,"/");
setcookie ("cookieb", "foo", $lifetime,"/");
setcookie ("cookiec", "doo", $lifetime,"/");
Only cookiec would be set. cookiea and cookieb would NOT be set.

This condition prevented login on phpmac.com.

NEWS FLASH

This has been fixed, our php has been patched.

FIX HOW-TO

edit ext/standard/head.c line 124

change

Code: Select all

return sapi_add_header(cookie, strlen(cookie), 0);
to

Code: Select all

return sapi_add_header_ex(cookie, strlen(cookie), 0, 0
TSRMLS_CC);

REFERENCES AND CREDIT
regina@hitel.net has provided the patch.

more information at http://bugs.php.net/bug.php?id=16626