PHP - 从另一个源/url 检测请求 php 页面的传入 url [英] PHP - Detect the incoming url requesting php page from another source/url

查看:32
本文介绍了PHP - 从另一个源/url 检测请求 php 页面的传入 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以检测在我的 php 页面中调用的 URL,类似于 GET 或 POST 但想要获取 URL,因为我想将访问它的页面限制为某个 URL因为这个文件是从另一台服务器调用的.

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.

基本上:如果 URL 不是 www.MYURL.com,www.MYURL.com 会从 www.PHPURL.com 调用 php 文件,然后将它们退回等.

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.

非常感谢

为了回应下面的答案,我使用了 as mentioend,这是我所做的:

In response to the answers below I used the as mentioend and here is what I did:

  $URL_REF = parse_url($_SERVER['HTTP_REFERER']);
  $URL_REF_HOST =   $URL_REF['host'];

感谢@Philip Bevan、@Itai Sagi 和@EvilP

Thanks @Philip Bevan,@Itai Sagi and @EvilP

推荐答案

好吧,你可以使用 $_SERVER['HTTP_REFERER'] - 但它可以被隐藏/移除.

well, you could use $_SERVER['HTTP_REFERER'] - but it can be cloaked/removed.

正如有人问的那样,HTTP_REFERER 是客户端发送的标头,大多数浏览器的默认行为是发送它,但如果您愿意,可以禁用它,甚至可以发送不同的引用标头,以便人们会认为你来自其他地方.

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.

底线:如果它对您来说不是那么重要,您可以使用它,但永远不要仅根据他们的推荐人给予人们额外的特权.

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.

这篇关于PHP - 从另一个源/url 检测请求 php 页面的传入 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆