Edit report at http://bugs.php.net/bug.php?id=52272&edit=1
ID: 52272
Comment by: kentaro at ranvis dot com
Reported by: saprykin dot dmitry at gmail dot com
Summary: header() replace param works strange
Status: Open
Type: Bug
Package: Output Control
Operating System: Linux
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
The second parameter 'replace' for header() function only replaces the first
header found in FIFO manner, retaining all the remaining headers.
cf. main/SAPI.c calling zend_llist_del_element() in Zend/zend_llist.c (looked
5.3 branch and trunk)
Test script:
---------------
<?php
header('X-Foo: 1', true);
header('X-Foo: 2', false);
print_r(headers_list());
header('X-Foo: 3', true);
print_r(headers_list());
header('X-Foo: 4', false);
print_r(headers_list());
header('X-Foo: 5', true);
print_r(headers_list());
Expected result:
----------------
Array
(
[0] => X-Powered-By: PHP/5.3.6
[1] => X-Foo: 1
[2] => X-Foo: 2
)
Array
(
[0] => X-Powered-By: PHP/5.3.6
[1] => X-Foo: 3
)
Array
(
[0] => X-Powered-By: PHP/5.3.6
[1] => X-Foo: 3
[2] => X-Foo: 4
)
Array
(
[0] => X-Powered-By: PHP/5.3.6
[1] => X-Foo: 5
)
Actual result:
--------------
Array
(
[0] => X-Powered-By: PHP/5.3.6
[1] => X-Foo: 1
[2] => X-Foo: 2
)
Array
(
[0] => X-Powered-By: PHP/5.3.6
[1] => X-Foo: 2
[2] => X-Foo: 3
)
Array
(
[0] => X-Powered-By: PHP/5.3.6
[1] => X-Foo: 2
[2] => X-Foo: 3
[3] => X-Foo: 4
)
Array
(
[0] => X-Powered-By: PHP/5.3.6
[1] => X-Foo: 3
[2] => X-Foo: 4
[3] => X-Foo: 5
)
Previous Comments:
------------------------------------------------------------------------
[2010-07-07 12:12:34] saprykin dot dmitry at gmail dot com
Description:
------------
1) Output m headers with the same name using header($header, false)
2) Output n (n > m) headers with the same name using header($header, true)
Result) headers will not be replaced totally.
Script will send to output m last headers sent by header($header, true).
Test script:
---------------
<?php
/**
* PHP VERSION 5.3.0
*/
header('Set-Cookie: name1=; path=/; domain=.simple.ru', false);
header('Set-Cookie: name2=; path=/; domain=.simple.ru', false);
header('Set-Cookie: name3=; path=/; domain=.simple.ru', true);
header('Set-Cookie: name4=; path=/; domain=.simple.ru', true);
header('Set-Cookie: name5=; path=/; domain=.simple.ru', true);
print_r(headers_list());
?>
Expected result:
----------------
Array
(
[0] => Set-Cookie: name5=; path=/; domain=.simple.ru
)
Actual result:
--------------
Array
(
[0] => Set-Cookie: name4=; path=/; domain=.simple.ru
[1] => Set-Cookie: name5=; path=/; domain=.simple.ru
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52272&edit=1