PHP - 从另一个源/url 检测请求 php 页面的传入 url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9790771/
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
PHP - Detect the incoming url requesting php page from another source/url
提问by Simon Davies
Is there a way in which I can detect the URL that is calling in my php page, similar to say a GET or POST but would like to get the URL as I would like to restrict the page accessing it to a certain URL as this file is being called from another server.
有没有一种方法可以检测在我的 php 页面中调用的 URL,类似于 GET 或 POST 但想要获取 URL,因为我想将访问它的页面限制为某个 URL 作为这个文件正在从另一台服务器调用。
Basically: www.MYURL.com calls the php file from say www.PHPURL.com if the URL is NOT www.MYURL.com then bounce them out etc.
基本上:如果 URL 不是 www.MYURL.com,www.MYURL.com 会从 www.PHPURL.com 调用 php 文件,然后将它们弹出等。
Many Thanks
非常感谢
In response to the answers below I used the as mentioend and here is what I did:
为了回应下面的答案,我使用了 as mentioend,这是我所做的:
$URL_REF = parse_url($_SERVER['HTTP_REFERER']);
$URL_REF_HOST = $URL_REF['host'];
Thanks @Philip Bevan,@Itai Sagi and @EvilP
感谢@Philip Bevan、@Itai Sagi 和@EvilP
回答by Itai Sagi
well, you could use $_SERVER['HTTP_REFERER']
- but it can be cloaked/removed.
好吧,你可以使用$_SERVER['HTTP_REFERER']
- 但它可以被隐藏/移除。
EDIT: as someone asked, the HTTP_REFERER is a header which is sent by the client, most browsers default behavior is to send it, but if you'd like, you can disable it or even send a different referer header so people will think you come from some place else.
编辑:正如有人问的,HTTP_REFERER 是由客户端发送的标头,大多数浏览器的默认行为是发送它,但如果您愿意,您可以禁用它甚至发送不同的引用标头,以便人们会认为您来自其他地方。
the bottom line: if it isn't THAT critical for you, you can use it, but don't EVER, EVER give people extra privileges based on their referer alone.
底线:如果它对您来说不是那么重要,您可以使用它,但永远不要仅根据他们的推荐人给予人们额外的特权。
回答by mas-designs
$_SERVER["HTTP_REFERER"]
is what you are looking for.
就是你要找的。