what can be php script to Redirect visitors of a wapsite based on Multi Respected Referrer

246 views Asked by At

I am trying to redirect Visitors to a site based on their referrer url.

Visitors coming from "x" should be redirected to "x1" and Visitors coming from "y" should be redirected to "y1" and so on....

Here x and y are any website url(SOURCE) & x1 and y1 are also website url but these are DESTINATION..

i am trying to do the same with below written but its not working...

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

There are 2 answers

2
user1906399 On BEST ANSWER

Lets say you have a page x.php which is in the server and y.php which a particular user is comming from.

Code for y.php

    <?php

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

Code for 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);

    }

?>
4
LucaP On

You can use to get the referrer

$_SERVER["HTTP_REFERER"]

and to redirect:

header('location: http://...')