php $_SERVER['HTTP_REFERER'] 的结果,当引用标头未发送到服务器时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13948267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:20:05  来源:igfitidea点击:

Result from $_SERVER['HTTP_REFERER'], when referer header is not sent to server

phpurlhttp-headers

提问by Oto Shavadze

When the browser sends header info to the server, $_SERVER['HTTP_REFERER']should give us the previous page URL right?

当浏览器向服务器发送头信息时,$_SERVER['HTTP_REFERER']应该给我们上一页的 URL 对吗?

What returns from $_SERVER['HTTP_REFERER'], when header info is not sent to server? empty string? false? null? or... ?

$_SERVER['HTTP_REFERER']当标头信息未发送到服务器时,返回什么?空字符串?错误的?空值?或者... ?

采纳答案by MrWhite

If the HTTP referer request header is not sent then the $_SERVER['HTTP_REFERER']is probably not set, although it could be an empty string. Whether it is set or not in this case could depend on the server.

如果未发送 HTTP 引用请求标头,$_SERVER['HTTP_REFERER']则可能未设置,尽管它可能是空字符串。在这种情况下是否设置可能取决于服务器。

As with all HTTP request headers, check for its existence when reading:

与所有 HTTP 请求标头一样,在阅读时检查它是否存在:

$httpReferer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;

回答by Shoe

$_SERVER['HTTP_REFERER']is not really reliable because particular setting on the user browser could break it. But yes it should contain the previous URL and it will return empty string or NULL when headers are not sent, depending on the server configuration.

$_SERVER['HTTP_REFERER']不是很可靠,因为用户浏览器上的特定设置可能会破坏它。但是是的,它应该包含以前的 URL,并且在不发送标头时它将返回空字符串或 NULL,具体取决于服务器配置。

回答by wau

$_SERVER is a global array variable, and the referrer value is an element of the array with key HTTP_REFERER. If is no referrer header is sent by the browser, then the element is simply missing from the array. You can check whether an array has an element with array_key_exists; in this case:

$_SERVER 是一个全局数组变量,referrer 值是键为 HTTP_REFERER 的数组元素。如果浏览器没有发送引用标头,则该元素只是从数组中丢失。您可以使用array_key_exists来检查数组是否具有元素;在这种情况下:

array_key_exists('HTTP_REFERER', $_SERVER)

array_key_exists('HTTP_REFERER', $_SERVER)