Ask a Question related to PHP Development, Design and Development.
-
seairth at cox dot net #1
#25044 [NEW]: header("Location:") changing HTTP status
From: seairth at cox dot net
Operating system: N/A
PHP version: Irrelevant
PHP Bug Type: HTTP related
Bug description: header("Location:") changing HTTP status
Description:
------------
When setting the "Location" HTTP header using the header() function, PHP
automatically changes the HTTP response status to "302 Found". However,
there are several other legitimate status codes that use the Location
header. These codes include 201, 301, 303, 305, and 307 (according to the
HTTP 1.1 spec). When one of these status codes is already set, setting
the Location header should not change it.
Note: there is a workaround. (re)Set the status after setting the
Location header. However, this is not a reasonable solution. For those
codes listed above, it should not matter whether the status is set before
or after the Location header.
It may even be appropriate to not change the status for any value other
than 200 (the default). As a result, if a user explicitly sets the status
to something other than 200, then setting the Location header should not
change that value again (even if the combination of the status and header
do not make sense). The reasoning here is that HTTP status codes are
extensible, meaning that new specifications can add new status codes that
may use the Location header. If only testing for the above list, new
codes would be overlooked and therefore automatically changed.
Reproduce code:
---------------
header('HTTP/1.1 201 Created');
header("Location: http://www.php.net/");
Expected result:
----------------
HTTP Response:
HTTP/1.1 201 Created
Location: [url]http://www.php.net/[/url]
Actual result:
--------------
HTTP Response:
HTTP/1.0 302 Found
Location: [url]http://www.php.net/[/url]
--
Edit bug report at [url]http://bugs.php.net/?id=25044&edit=1[/url]
--
Try a CVS snapshot (php4): [url]http://bugs.php.net/fix.php?id=25044&r=trysnapshot4[/url]
Try a CVS snapshot (php5): [url]http://bugs.php.net/fix.php?id=25044&r=trysnapshot5[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=25044&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=25044&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=25044&r=needtrace[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=25044&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=25044&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=25044&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=25044&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=25044&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=25044&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=25044&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=25044&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=25044&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=25044&r=gnused[/url]
seairth at cox dot net Guest
-
Webservice problem: "The Request failed with http status 401"
Okay, I'm writing a plugin for Outlook 2003 using C# and the .Net framework. In this plugin I'm opening a windows form that should fetsch some data... -
Getting "The request failed with HTTP status 403: Error" ??
I have a webservice that returns PDF generated reports. This service works fine retuning various reports, but some reports quickly fail with the... -
querystring problem after using header("Location:xxx")
On "page1.php?aaa=1" I do a redirect to remove the variables in the querystring that I don't need anymore: header("Location: page1.php?bbb=1") ;... -
Fuction which is similar to header ("Location: script.php")
Andrzej wrote: It sounds like you need to check for the condition before outputting "lalalala", or restructure your code in some kind of way. ... -
#25044 [Opn->Csd]: header("Location:") changing HTTP status
ID: 25044 Updated by: helly@php.net Reported By: seairth at cox dot net -Status: Open +Status: ...



Reply With Quote

