#47083 [NEW]: Making documentation of header()'s behaviour on Location: headers more specific
From: skrebbel at gmail dot com
Operating system: N/A
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: Making documentation of header()'s behaviour on Location: headers more
specific
Description:
------------
Note: I added the following as a manual note first, but Thiago Henrique
Pojda of php-notes rejected it with the recommendation that I file it as a
documentation bug. I make my conclusions based on
http://cvs.php.net/viewvc.cgi/php-src/main/SAPI.c?revision=1.232&view=markup.
----
The manual is not completely precise on what PHP does (at least
according to the PHP source in CVS) with Location: headers.
This is the actual behaviour when you specify a Location: header, as
far as I could derive:
- If in earlier header() calls(*), a status code 201 or 300 - 307 was
already specified, then that status code is retained
- If no status code was specified, or if the status code specified
earlier is not 201 or 300 ... 307 then:
- If the request method is GET or HEAD then 302 "Found" is set
- Otherwise (i.e. for POST or PUT), 303 "See Also" is set.
Finally, if in the same header call you specify a custom status code,
that one is always set (no matter its value), unless changed later
again.
Examples:
<?php
header("Location: http://www.foobar.com/");
?>
and
<?php
header("HTTP/1.1 404 Not Found");
header("Location: http://www.foobar.com/");
?>
set the status code to 302 when called with GET and to 303 when called
with POST, and
<?php
header("Location: http://www.foobar.com/",
true, 404);
?>
and
<?php
header("Location: http://www.foobar.com/");
header("HTTP/1.1 404 Not Found");
?>
set the status code to 404.
Note that combining a Location header with a status code other than
201 or 3xx does not really make much sense in HTTP <= 1.1 (hence PHP's
behaviour); as such, the last three examples are just for illustrative
purposes.
(*) either through a header("HTTP/1.1 302 Found") - style call or
through the third argument on a different header() call, i.e.
header("Content-type: text/html", true, 302); (which does not make
much sense, though)
--
Edit bug report at http://bugs.php.net/?id=47083&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47083&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47083&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47083&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=47083&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47083&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=47083&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=47083&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=47083&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=47083&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=47083&r=support
Expected behavior: http://bugs.php.net/fix.php?id=47083&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=47083&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=47083&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=47083&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47083&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47083&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=47083&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=47083&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=47083&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=47083&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=47083&r=mysqlcfg
Thread (2 messages)
- skrebbel at gmail dot com