note 30181 added to function.header
| From: | Martin at rack1 dot php dot net | Date: | Sun, 09 Mar 2003 21:24:09 +0000 |
| Subject: | note 30181 added to function.header | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45044@lists.php.net to get a copy of this message | ||
(PHP 4.2.1, PHP 4.3.1)
If you use a header('Location:...') call in your code, PHP will _always_ force your
document's HTTP status code to be 302 if you don't already specify a 3XX code (unless you
use http_response_code, below). However, the HTTP Specification states that an "HTTP/1.1 201
Created" is a valid status code to pair with a "Location:..." header.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30
So, I upgraded to 4.3.1 but the problem remained, luckily the http_response_code option was added to
the function call. I used header('Location:...', TRUE, 201). Now my server responses
were getting generated properly.
Then, horror. Neither browser I used (IE 6 SP1, Mozilla/Phoenix) redirected to my location when I
returned a "201 Created" code.
I'm not sure if 201 was ever intended for use with automatic redirection (probably not), but
since my redirects don't work with it. I'm resigned to using "HTTP/1.1 302
Found" redirects.
I guess the only problem I see is PHP not letting a header('HTTP/1.1 201 Created') exist
with a header('Location:...') without some forcing.
--
http://www.php.net/manual/en/function.header.php
http://master.php.net/manage/user-notes.php?action=edit+30181
http://master.php.net/manage/user-notes.php?action=delete+30181
http://master.php.net/manage/user-notes.php?action=reject+30181