Bug #36705 [Com]: Location header results in duplicate Status header ([f]cgi only)

From: Date: Thu, 24 Jun 2010 09:39:06 +0000
Subject: Bug #36705 [Com]: Location header results in duplicate Status header ([f]cgi only)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-151831@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=36705&edit=1

 ID:               36705
 Comment by:       hanskrentel at yahoo dot de
 Reported by:      alisencer at gmail dot com
 Summary:          Location header results in duplicate Status header
                   ([f]cgi only)
 Status:           Closed
 Type:             Bug
 Package:          Unknown/Other Function
 Operating System: FreeBSD
 PHP Version:      5.1.2

 New Comment:

This was reported to work for 5.3.0 I was curious how that behaves on
5.2.x and did run a test. It works, here are the details:

PHP 5.2.6 (cgi-fcgi) (built: May  2 2008 18:02:06)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
    with Xdebug v2.0.0RC4-dev, Copyright (c) 2002, 2003, 2004, 2005,
2006, 2007, by Derick Rethans

Status: 301
Location: http://www.example.org
Content-type: text/html


Previous Comments:
------------------------------------------------------------------------
[2008-04-13 23:36:23] bjori@php.net

bjori@lindsay:~$ ./php/5.3/sapi/cgi/php-cgi 
<?php
header("Status: 301");
header("Location: http://www.example.org");
?>
X-Powered-By: PHP/5.3.0-dev
Status: 301
Location: http://www.example.org
Content-type: text/html; charset=utf-8

Works fine now...

------------------------------------------------------------------------
[2006-12-07 20:21:29] chris at vault5 dot com

This bug is filed against FreeBSD but it is certainly not limited to
that OS.

Using the Microsoft IIS FastCGI ISAPI extension this issue occurs on
IIS, too.

------------------------------------------------------------------------
[2006-05-03 18:37:20] phpbugs at thequod dot de

As far as I remember from looking around because of the 
already mentioned "bogus" bug 
http://bugs.php.net/bug.php?id=33225:

The CGI spec says that there should only be one Status 
header.

In my humble opinion, PHP should take care of sending only 
one status header.

In the case of "Location:" any existing one should get 
overwritten and not added.

------------------------------------------------------------------------
[2006-04-22 07:57:34] bryan at b1t5 dot com

The most effective workaround is to just edit mod_fastcgi.c
------------------------------------
if (strcasecmp(name, "Status") == 0) {
            int statusValue = strtol(value, NULL, 10);

            if (hasStatus) {
                /* comment out the braindead line below */
                /* goto DuplicateNotAllowed;            */
            }
            if (statusValue < 0) {
                fr->parseHeader = SCAN_CGI_BAD_HEADER;
                return ap_psprintf(r->pool, "invalid Status '%s'",
value);
            }
            hasStatus = TRUE;
            r->status = statusValue;
            r->status_line = ap_pstrdup(r->pool, value);
            continue;
        }
------------------------------------
apache doesn't care how many times you set r->status. Set it once,
twice, 500 times even -- it doesn't matter cuz r is just a struct you
fill up before calling ap_send_http_header(r)

------------------------------------------------------------------------
[2006-03-13 03:55:42] judas dot iscariote at gmail dot com

as an effective workaround to this problem, you can use PEAR HTTP_Header
class. 

hint : method sendStatusCode()

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=36705


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=36705&edit=1


Thread (4 messages)

« previous php.bugs (#151831) next »