-3

我正在尝试根据访客的引荐来源网址将访客重定向到网站。

来自“x”的访问者应该被重定向到“x1”,来自“y”的访问者应该被重定向到“y1”等等......

这里 x 和 y 是任何网站 url(SOURCE) & x1 和 y1 也是网站 url 但这些是 DESTINATION..

我正在尝试对以下内容做同样的事情,但它不起作用......

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

2 回答 2

2

您可以使用来获取推荐人

$_SERVER["HTTP_REFERER"]

并重定向:

header('location: http://...')
于 2014-01-01T17:51:14.223 回答
1

假设您有一个位于服务器中的页面 x.php 和一个特定用户来自的 y.php。

y.php 的代码

    <?php

     <a href="x.php">go to x</a>
    ?>

x.php 的代码

    <?php
    if(isset($_SERVER['HTTP_REFERER'])){//checking if user comming from other page or came here directly

       $referer = $_SERVER['HTTP_REFERER'];
    }

//now the $referer holds path of y page
//now you can use it to redirect

    if(//some condition){
      heder('Location:'.$referer);

    }

?>
于 2014-01-01T18:20:09.113 回答