检查特定网址的引荐来源网址

发布于 2024-10-03 00:49:57 字数 444 浏览 0 评论 0原文

我的每个网站页面的顶部都有一些设备重定向 PHP,如果从某个 url 访问该页面,我想禁用这些设备重定向 PHP。

如果用户通过点击 http://www.mysite.com/mobile 到达该页面,如何禁用此 PHP

该网址可能会更改,即: http://www.mysite.com/mobile/ blah/blahhttp://mysite.com/mobile/blah/

我只是需要检查“mysite.com/mobile”部分。

I have some device redirection PHP at the top of each of my sites pages that I want to disable if the page was reached from a certain url.

How can I disable this PHP if the user arrived at that page by clicking from http://www.mysite.com/mobile

That url could change, ie: http://www.mysite.com/mobile/blah/blah or http://mysite.com/mobile/blah/

I just need to check for the 'mysite.com/mobile' part.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绾颜 2024-10-10 00:49:57

您可以使用:

$_SERVER['REQUEST_URI'] 和 $_SERVER['REQUEST_URL']

基本上你会想检查你在哪里:

if($_SERVER["REQUEST_URI"]!="/mobile/index.php"){
    header("location: ");
    exit;
}

You can use either:

$_SERVER['REQUEST_URI'] and $_SERVER['REQUEST_URL']

Basically you would want to check where you are at:

if($_SERVER["REQUEST_URI"]!="/mobile/index.php"){
    header("location: ");
    exit;
}
椒妓 2024-10-10 00:49:57

您需要从标题中获取引荐来源网址。例如,检查@$HTTP_REFERER 是否等于'http://www.mysite.com/mobile',然后进行相应的编码。

如果引用 URL 将发生更改,那么您可能需要拼接引用网址以查找主机和某些路径,例如“/mobile”。如果不是,并且您有可能的引用 URL 的常量列表,那么您只需循环遍历 URL 并根据 @$HTTP_REFERER 变量检查它们即可。

You need to grab the referrer from the header. e.g. Check if @$HTTP_REFERER is equal to 'http://www.mysite.com/mobile' and then code accordingly.

If the referring URL is going to change, then you may need to splice the referrer out to look for the host, and certain path's such as '/mobile'. If it's not, and you have a constant list of possible referring URLs, then you'll simply need to loop through the URLs and check them against the @$HTTP_REFERER variable.

罗罗贝儿 2024-10-10 00:49:57
 <?php 
 echo $HTTP_REFERER; 
 ?> 

页面引用地址是通过使用 $HTTP_REFERER 变量找到的。这是一种快速查找人们从何处导航到您的页面的方法。一旦您知道此信息,您还可以根据它过滤用户。例如,您只允许来自您的推荐页面之一的人使用您的下载部分等。
不幸的是 $HTTP_REFERER 并不是万无一失的。有些浏览器不发送此信息,或者可以发送虚假信息。使用 $HTTP_REFERER 时应记住这一点。

 <?php 
 echo $HTTP_REFERER; 
 ?> 

The page referrer is found by using the $HTTP_REFERER variable. This is a quick way of looking up where people are navigating to your pages from. Once you know this information you can also filter users based upon it. For example, you only let people who come from one of your referring pages to use your downloads section, etc.
Unfortunately $HTTP_REFERER is not foolproof. Some browsers do not send this information, or can be made to send false information. You should keep this in mind when working with $HTTP_REFERER.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文