Search code examples
phpreferrer

Is there a way to forward the referrer when sending the user to a different domain?


I have a site that works off several TLDs. I want to save the initial referrer, from where the user came from, before they are redirected to the correct domain. After the redirect, the referrer is obviously rewritten (and it wont read cookies or sessions set on another domain).

is there a way I could pass it in a GET variable when redirecting, and then overwrite it once the user lands on the domain, so it could be saved if they register to the site.

I use php.


Solution

  • <?php
    // on the first domain
    header("Location: http://newdomain.com/?referrer=".urlencode($_SERVER['HTTP_REFERRER']));
    die();
    

    Then on the correct domain you can just get the referrer using $_GET['referrer'].