0

I am trying to get something. I have a page which for example is http://www.example.com/mypage.php I have created PHP code to get referrer URL which is working perfectly.

    <?php
    //get pg referer if there is one
        if (isset($_SERVER['HTTP_REFERER'])) {
        $ref_url = $_SERVER['HTTP_REFERER']; //get referrer
      }else{
        $ref_url = 'No referrer set'; // show failure message
        }//end else no referer set
    ?>

Now what i want is when I open http://www.example.com/mypage.php using any referrer link i want that link to become "http://www.example.com/mypage.php?referrer=referrerlink" on the browser so when i am coming from google.com by clicking mypage.php so browser should show "http://www.example.com/mypage.php?referrer=google.com

Is that possible?

Regards Manoj Soni

Manoj Soni
  • 73
  • 7
  • Duplicate of URL Rewriting with PHP, See https://stackoverflow.com/questions/16388959/url-rewriting-with-php although in your case, you should just have the referrer send you the url in the form you are asking rather then rewriting it on your side. If you are using this for google analytics, they can tell who the referrer is without the url being rewritten – SteveB Jan 23 '18 at 13:33

1 Answers1

0

Maybe you can do it with header location like this.

<?php
//get pg referer if there is one
if (isset($_SERVER['HTTP_REFERER']) && !isset($_GET['referrer'])) {
    header("location: ?referrer=".urlencode($_SERVER['HTTP_REFERER']));
    exit();
}else{
    if (isset($_GET['referrer'])) {
        $referrer = $_GET['referrer'];
    } else {
        $ref_url = 'No referrer set'; // show failure message
    }
}//end else no referer set
Ammar Faizi
  • 1,393
  • 2
  • 11
  • 26