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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
29 - 12 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 01:01:28 2024 UTC