What\'s the difference between the function \"HTTP_redirect\"
and \"header location\"
in PHP ?
When must I use the function \"HTTP_re
Header forwards the user to a new page, so PHP reinitializes, it's like a HTML meta redirection, but faster.
http_redirect
is basically a helper function, making it easier to use header location
by allowing you to pass an array for GET data.
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>.