note 88131 added to function.header
| From: | skrebbel at gmail dot com | Date: | Mon, 12 Jan 2009 11:24:31 +0000 |
| Subject: | note 88131 added to function.header | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149086@lists.php.net to get a copy of this message | ||
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)
----
Server IP: 83.137.20.135
Probable Submitter: 131.155.68.193
----
Manual Page -- http://www.php.net/manual/en/function.header.php
Edit -- https://master.php.net/note/edit/88131
Del: integrated -- https://master.php.net/note/delete/88131/integrated
Del: useless -- https://master.php.net/note/delete/88131/useless
Del: bad code -- https://master.php.net/note/delete/88131/bad+code
Del: spam -- https://master.php.net/note/delete/88131/spam
Del: non-english -- https://master.php.net/note/delete/88131/non-english
Del: in docs -- https://master.php.net/note/delete/88131/in+docs
Del: other reasons-- https://master.php.net/note/delete/88131
Reject -- https://master.php.net/note/reject/88131
Search -- https://master.php.net/manage/user-notes.php