How to null and/or alter the value of referring URL?

I'm using Google Analytics and other some Analytics services. I found they are tracking Referral URL.

So I want to hide Referral URL from Traffic Analysis Tools

(e.g.:- modify $_SERVER["HTTP_REFERER"]; value to on localhost)


<a href="get_referer.php"> Click Here</a>


    $referer = $_SERVER["HTTP_REFERER"];
    echo $referer ;

Recommended Answers

All 6 Replies

If I understood your request, I think it cannot be done.
Since Google Analytics runs into an external javascript file, which is located in:

Or for SSL:

The referer cannot be changed by your server, but only by a client browser. This happens because when a page is opened, the browser sends the headers to all the resources requested by the page, including all the external files. So Google Analytics is creating a direct connection [browser] -> [google-analytics] without including your server, i.e. nothing like this: [browser] -> [your_server] -> [google-analytics]. The association with your website is done by the tracker ID code.

Also I can’t think a proper way that can be done. But a cheat answer would be to redirect a request to the same url if it hasn’t been redirected yet, server side with PHP and headers. The easy way to know if that URL has been redirected server side, not redirect it if so could be using a SESSION variable for example. This could be trickier if there is a POST request, but can be done too.
Edit: Of course that way you just “hide” the referrer to the current uri not cheat that the referrer is another one.

as per my knowledge, It can be done. I have seen this on many traffic generating site. You can check this

Addons are available for firefox

I just want to do this with coding. I want to add code on my site which will null the Referer Value

For php it is, $_SERVER["HTTP_REFERER"];
For javascript it is, document.referrer,

but I'm not successful to write referrer instead localhost

@vizz if you are referring only to a local script to run, then yes it can be done:

    $ref_url = ''; # this is the Referer
    $url = 'http://your_website.tld/target.php';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, $ref_url);
    echo curl_exec ($ch);
    curl_close ($ch);

But it works only if the request starts from a script (the above) asking for a page. Not sure if this is helpful for you, bye!

Any analytics tool that uses Javascript (basically all of them) just gets the referer from document.referrer in the DOM. This can't be overwritten with your own value but a lot of times the analytics tools let you override them. I work for an analytics company and we have a method as well.

Here is one for Google Analytics.

I really don't see a good reason to override the referer in analytics.. that is one of the major parts of web analytics.

commented: thanks for sharing +11

It is possible to cheat with Google Analytics in firefox using addons.

But how to do the same thing using php or javascript, like addons I posted above?

I have tested above addons, 1st one hides referer from Google Analytics

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.