php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52272 header() replace param works strange
Submitted: 2010-07-07 12:12 UTC Modified: 2013-08-01 13:01 UTC
Votes:5
Avg. Score:3.2 ± 0.7
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (66.7%)
From: saprykin dot dmitry at gmail dot com Assigned: mike (profile)
Status: Closed Package: Output Control
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: saprykin dot dmitry at gmail dot com
New email:
PHP Version: OS:

 

 [2010-07-07 12:12 UTC] 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
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-06-06 13:56 UTC] kentaro at ranvis dot com
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
)
 [2013-08-01 13:01 UTC] mike@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: mike
 [2013-08-01 13:01 UTC] mike@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 16:01:31 2025 UTC