问题
What's the difference between the function "HTTP_redirect" and "header location" in PHP ?
When must I use the function "HTTP_redirect" ?
When must I use the function "header location" ?
Look that: http://php.net/manual/fr/function.http-redirect.php --> Manual for HTTP_redirect http://php.net/manual/fr/function.header.php --> Manual for the function header
回答1:
http_redirect is basically a helper function, making it easier to use header location by allowing you to pass an array for GET data.
回答2:
1) Header in PHP
header() function sends a raw HTTP header to a client.
<?php
header("HTTP/1.0 404 Not Found");
?>
The above (taken from the PHP documentation) sends a 404 header back to the client.
2) HTTP Redirect
Redirect to the given url.
<?php
http_redirect("relpath", array("name" => "value"), true, HTTP_REDIRECT_PERM);
?>
The above (taken from the PHP documentation) : Output
HTTP/1.1 301 Moved Permanently
X-Powered-By: PHP/5.2.2
Content-Type: text/html
Location: http://www.example.com/curdir/relpath?name=value&PHPSESSID=abc
Redirecting to <a href="http://www.example.com/curdir/relpath?name=value&PHPSESSID=abc">http://www.example.com/curdir/relpath?name=value&PHPSESSID=abc</a>.
回答3:
Header forwards the user to a new page, so PHP reinitializes, it's like a HTML meta redirection, but faster.
来源:https://stackoverflow.com/questions/14353130/php-header-location-vs-php-redirect