Javascript/PHP Script that Hides Referring URLs

Drop Referring URLsYou may be wondering why in the world would you ever want to hide a referring url? Well, for several reasons really.

  • Private ‘research’ Forums that link and share Websites, Content and Web Tools. This tool will ensure the original referring url is hidden, helping keep private areas unknown to statistic programs.
  • The script can be hosted on a remote domain so the original referring Website is masked.
  • Any Website linking to an online tools direct-backend url, like a rank checking site.
  • It can be used to help kill new user link spam from WordPress comments or Forums.
  • Use it to kill search engine link benefits from open forums or any public website that posts links.



The Script

The hide referrer script is rather simple. The reason it hides the original referring source is due to the javascript redirect. If it was a php redirect, it would pass through the referring url, unless it paused and required another click. The rest of the script keeps it from being abused by others.

<?php /** Hide the Original Referring URL of a link */
/** Location to redirect errors to */
$error_redirect = '';
/** Local Host Check */
$host_check = $_SERVER['HTTP_HOST'];
if ( $host_check  != "" ) { header( "Location: $error_redirect" ); }
/** IP Check */
//$check_url = getenv("REMOTE_ADDR");
//if ( $check_url != "" ) { header( "Location: $error_redirect" ); }
/** No $url Error */
$url = $_GET['url'];
if ( !$url ) { header( "Location: $error_redirect" ); }
/** Check URL Format */
if ( !preg_match( "/^(http|https):\/\//i", $url ) ) { echo "Error: URL is not formatted correctly."; exit; }
<script language="JavaScript"><!--
function go() {
    top.location = '<?=$url;?>'
<body onload="go()">

The Hide Referrer Script Within A Standalone WordPress Template

If you have a WordPress Website this is how you would add the script to a standalone WordPress Template.

The Standalone WordPress Template

  • Template Name: At the top of the file, commented out, is the Template Name: Hide Referrer. This makes WordPress display the template within the WordPress admin. When adding a New Page, under the Page Attributes widget, within the Templates dropdown, the template Hide Referrer will appear.
  • require('./wp-blog-header.php'); This is what makes the template actually work within WordPress. Without this the template will not function correctly.
 * Template Name: Hide Referrer
<!-- Hide Referrer Script Goes Here -->


  • Grab the template and name it: hide-referrer.php then paste the Hide Referrer Script above into the template. Save and upload the template to your active theme directory.
  • Once done, log into your WordPress Admin and create a new page. Set the title to anything you like, then change the url of the page, to something like: track, visitor, redirect, or (t, v, r) etc.
  • Under the Page Attributes widget, within the Templates dropdown, select the template: Hide Referrer.
  • Publish the page.
  • Create a test link, example: