note 88131 rejected from function.header by thiago

From: Date: Mon, 12 Jan 2009 17:01:00 +0000
Subject: note 88131 rejected from function.header by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149106@lists.php.net to get a copy of this message
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)

« previous php.notes (#149106) next »