你如何在 PHP 中获得“referer”标头?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1031162/
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 00:42:39  来源:igfitidea点击:

How do you get the 'referer' header in PHP?

phphttp-headers

提问by Abdulsattar Mohammed

I want the the url of the page from which a request has been made. How can I do that in PHP?

我想要发出请求的页面的 url。我怎样才能在 PHP 中做到这一点?

回答by Stefan Gehrig

The refer(r)er can be found in the $_SERVERglobal variable. Please note that sending the refer(r)er is completely optional and a user-agent can simply decide to not send the refer(r)ing url.

引用(r)er 可以在$_SERVER全局变量中找到。请注意,发送refer(r)er 是完全可选的,用户代理可以简单地决定不发送refer(r)ing url。

$_SERVER['HTTP_REFERER']

回答by TFM

$_SERVER['HTTP_REFERER']

The documentations are available here here.

此处提供了文档。