如何重定向和/或延迟视引荐? [英] How to redirect and/or delay depending on referrer?

查看:189
本文介绍了如何重定向和/或延迟视引荐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许的流量到我的网站只能从类似example.com/123一定的参考网址。我想交通​​的其余部分特定的延迟后,被重定向到相同的引用URL,说1或2分钟。我想交通 来自example.com/123没有再被提及。

我想用这样的事情,但我不知道如何修改,以满足我的要求:

 < PHP
$引荐= $ _ SERVER ['HTTP_REFERER'];
如果(preg_match(/ site1.com/",$referrer)){
      头('位置:http://www.customercare.com/page-site1.html');
} ELSEIF(preg_match(/ site2.com/",$referrer)){
      头('位置:http://www.customercare.com/page-site2.html');
} 其他 {
      头('位置:http://www.customercare.com/home-page.html');
};
?>
 

解决方案

您需要有东西在你的PHP脚本,影响的头,而不是实际的头服务器响应。

因此​​,在生成网页的标题脚本的一部分,你需要的是这样的:

 <! - 这就是你的页面的标题 - >
< HEAD>
  <冠军>你的标题< /标题>
  < PHP
    $引荐= $ _ SERVER ['HTTP_REFERER'];

    //如果引用者是不是从example.com/123我们设置一个重定向
    如果(的strstr($引荐,!://example.com/123'))
       打印('< META HTTP-EQUIV =刷新内容=60; URL = HTTP://example.com/123> \ N');

    ?>
  <  - !也许一些其他的东西 - >
< /头>
 

因此​​,如果引用者的不是的距离 http://example.com/123 ,则该行会被插入到页眉

 < META HTTP-EQUIV =刷新内容=60; URL = HTTP://example.com/123>
 

告诉浏览器重定向到URL(在这种情况 http://example.com/123 )60秒后

I want to allow traffic to my site only from a certain referring URL like "example.com/123". I want the rest of traffic to be redirected to the same referring URL after a particular delay, say 1 or 2 minutes. I want the traffic that comes from example.com/123 not to be referred anymore.

I thought of using something like this but I have no clue how to edit to meet my requirements:

<?php
$referrer = $_SERVER['HTTP_REFERER'];
if (preg_match("/site1.com/",$referrer)) {
      header('Location: http://www.customercare.com/page-site1.html');
} elseif (preg_match("/site2.com/",$referrer)) {
      header('Location: http://www.customercare.com/page-site2.html');
} else {
      header('Location: http://www.customercare.com/home-page.html');
};
?>

解决方案

You'll need to have something in your php script that affect the header of the page, and not the header of the actual server response.

So in the part of the script that generates the header of your pages, you need something like this:

<!-- this is the header of your page -->
<head>
  <title>Your Title</title>
  <?php
    $referrer = $_SERVER['HTTP_REFERER'];

    // if referer isn't from example.com/123 we setup a redirect
    if ( !strstr($referrer, '://example.com/123') )
       print ('<META HTTP-EQUIV=Refresh CONTENT="60; URL=http://example.com/123">\n');

    ?>
  <!-- maybe some other stuff -->
</head>

So if the referer isn't from http://example.com/123, then this line will be inserted into the header:

<META HTTP-EQUIV=Refresh CONTENT="60; URL=http://example.com/123">

which tells the browser to redirect to the URL (in this case http://example.com/123) after 60 seconds.

这篇关于如何重定向和/或延迟视引荐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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