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

StackOverflow https://stackoverflow.com/questions/20871393

  •  23-09-2022
  •  | 
  •  

سؤال

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

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

    }

?>

نصائح أخرى

You can use to get the referrer

$_SERVER["HTTP_REFERER"]

and to redirect:

header('location: http://...')
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top