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: http://www.php.net/ Actual result: -------------- HTTP Response: HTTP/1.0 302 Found Location: http://www.php.net/ -- Edit bug report at http://bugs.php.net/?id=25044&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25044&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25044&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=25044&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=25044&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=25044&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=25044&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=25044&r=support Expected behavior: http://bugs.php.net/fix.php?id=25044&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=25044&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=25044&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=25044&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25044&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=25044&r=dst IIS Stability: http://bugs.php.net/fix.php?id=25044&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=25044&r=gnused