Fwd: [PHP-NOTES] note 88131 rejected from function.header by thiago
| From: | Thiago Pojda | Date: | Mon, 12 Jan 2009 16:53:24 +0000 |
| Subject: | Fwd: [PHP-NOTES] note 88131 rejected from function.header by thiago | ||
| References: | 1 2 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149107@lists.php.net to get a copy of this message | ||
Hello,
Your note is good, please don't take this as a offense.
It was rejected because it has good information and should be better
placed in the docs.
Please report it as a documentation bug so we can find a better place for it. :)
Thank you for your effort,
Thiago Henrique Pojda
---------- Forwarded message ----------
From: <thiago@php.net>
Date: Mon, Jan 12, 2009 at 2:01 PM
Subject: [PHP-NOTES] note 88131 rejected from function.header by thiago
To: php-notes@lists.php.net
Note Submitter: skrebbel at gmail dot com
----
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: moo.html");
?>
and
<?php
header("HTTP/1.1 404 Not Found");
header("Location: moo.html");
?>
set the status code to 302 when called with GET and to 303 when called
with POST, and
<?php
header("Location: moo.html", true, 404);
?>
and
<?php
header("Location: moo.html");
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)