简体   繁体   English

php标题位置vs php_redirect

[英]php header location vs php_redirect

What's the difference between the function "HTTP_redirect" and "header location" in PHP ? PHP中的函数"HTTP_redirect""header location"之间有什么区别?

When must I use the function "HTTP_redirect" ? 什么时候必须使用"HTTP_redirect"功能?

When must I use the function "header location" ? 什么时候必须使用"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 看看: http ://php.net/manual/fr/function.http-redirect.php - > HTTP_redirect手册http://php.net/manual/fr/function.header.php - >手册函数头

http_redirect基本上是一个辅助函数,允许您为GET数据传递数组,从而更容易使用header location

1) Header in PHP 1) PHP中的标题

header() function sends a raw HTTP header to a client. header()函数将原始HTTP标头发送到客户端。

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

The above (taken from the PHP documentation) sends a 404 header back to the client. 上面(取自PHP文档)将404标头发送回客户端。

2) HTTP Redirect 2) HTTP重定向

Redirect to the given url. 重定向到给定的网址。

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

The above (taken from the PHP documentation) : Output 以上(取自PHP文档):输出

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>.

标题将用户转发到新页面,因此PHP重新初始化,就像HTML元重定向一样,但速度更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM