Php vs php_redirect header location

What is the difference between the functions "HTTP_redirect" and "header location" in PHP?

When should I use the "HTTP_redirect" function?

When should I use the "header location" function?

See what: http://php.net/manual/fr/function.http-redirect.php → Guide for HTTP_redirect http://php.net/manual/fr/function.header.php → Guide for the function header

+5
source share
3 answers

http_redirect is basically a helper function, which simplifies the use of header location , allowing you to pass an array for GET data.

+9
source

1) Header in PHP

Function

header () sends the raw HTTP header to the client.

 <?php header("HTTP/1.0 404 Not Found"); ?> 

The above (taken from the PHP documentation) sends back to client 404.

2) HTTP redirection

Redirect to the specified URL.

 <?php http_redirect("relpath", array("name" => "value"), true, HTTP_REDIRECT_PERM); ?> 

Above (taken from PHP documentation): Exit

 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>. 
+2
source

The header redirects the user to a new page, so PHP re-initializes it as an HTML meta-redirect, but faster.

0
source

All Articles