#36705 [Com]: Location header results in duplicate Status header ([f]cgi only)
| From: | ali dot sencer at gmail dot com | Date: | Sun, 12 Mar 2006 15:29:23 +0000 |
| Subject: | #36705 [Com]: Location header results in duplicate Status header ([f]cgi only) | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969372348@lists.php.net to get a copy of this message | ||
ID: 36705
Comment by: ali dot sencer at gmail dot com
Reported By: alisencer at gmail dot com
Status: Open
Bug Type: Documentation problem
Operating System: FreeBSD
PHP Version: 5.1.2
New Comment:
download and tried it (php5.1-200603121330)
$ ./php -v
PHP 5.1.3RC2-dev (cgi-fcgi) (built: Feb 20 2006 15:24:12)
...
sencer@dev:~/php5.1-200603121330/sapi/cgi$ echo "<?php header( 'Status:
301' );header( 'Location: http://www.example.org' );?>" | ./php
Status: 302
X-Powered-By: PHP/5.1.3RC2-dev
Status: 301
Location: http://www.example.org
Content-type: text/html
The bug is still present.
> One should not use "Status: 123" but "HTTP/1.x 123".
Did I miss an announcement? Since when is that? Using HTTP/1.x type
headers was not working on a variety of systems with (f)cgi, which is
why the following snippet was introduced (which is in a lot of
applications):
if (substr(php_sapi_name(), 0, 3) == 'cgi')
header("Status: $status");
else
header("HTTP/1.1 $status");
(which was the only solution that worked on all systems - until some
recent changes in newer releases.)
I could have sworn this was somehwere in the documentation even. So in
which versions was this changed? How can portable applications in PHP
be written, if these things change silently every now and then.
Why can header("Status: ") be used at all, if it's not supposed to be
used?
Can the behaviour at least be "fixed" in such a way, that (f)cgi won't
send "Status: " twice, which results in a 500 error by the webserver.
Thanks.
[edit: I am the bug-submitter, but must have mistyped my password]
Previous Comments:
------------------------------------------------------------------------
[2006-03-12 15:55:22] mike@php.net
Recalssifying as a documentation problem.
One should not use "Status: 123" but "HTTP/1.x 123".
------------------------------------------------------------------------
[2006-03-12 15:39:18] mike@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5.1-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.1-win32-latest.zip
------------------------------------------------------------------------
[2006-03-12 14:14:36] alisencer at gmail dot com
Description:
------------
In php-fastcgi, a header("Location: ..") call always results in an
additional "Status:" header. This causes the web server to throw a 500
Internal server error.
Identical code works perfectly in mod_php. The problem is specific to
fastcgi.
It doesn't matter what Status code the first header() call sends; the
"Location:" call always adds a second "Status: 302" line.
The effect is, that it becomes impossible to use
header("Location;..."), if at any previous point in the script a Status
header has been sent. It is also contrary to what the documentation
says:
http://de.php.net/manual/en/function.header.php
"The second special case is the "Location:" header. Not only does it
send this header back to the browser, but it also returns a REDIRECT
(302) status code to the browser unless some 3xx status code has
already been set."
(Note the last part of that paragraph)
Related: This seems to be what was happening in this bug report as
well: http://bugs.php.net/bug.php?id=33225 which
unfortunately was
closed as bogus.
Reproduce code:
---------------
$ echo "<?php header( 'Status: 301' );header( 'Location:
http://www.example.org' );?>" |
php/php-fastcgi/php5-fcgi
Expected result:
----------------
Content-type: text/html; charset=UTF-8
Status: 301
Location: http://www.example.com
Actual result:
--------------
Status: 302
Content-type: text/html; charset=UTF-8
Status: 301
Location: http://www.example.com
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=36705&edit=1