|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-03-12 14:14 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 18:00:01 2025 UTC |
I can't find a single evidence that a "Status:" header is treated differently than any other header in PHP versions 4.3, 4.4 and 5.1 -- and we can't do anything about Apache changing its behaviour. Why don't you just send the appropriate status header with the header() call? header("Location: uri", 1, 301);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)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...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