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 = 'https://technerdia.com/';
/** Local Host Check */
$host_check = $_SERVER['HTTP_HOST'];
if ( $host_check  != "technerdia.com" ) { header( "Location: $error_redirect" ); }
/** IP Check */
//$check_url = getenv("REMOTE_ADDR");
//if ( $check_url != "000.000.000.000" ) { 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; }
?>
<html>
<head>
<script language="JavaScript"><!--
function go() {
    top.location = '<?=$url;?>'
}
//-->
</script>
</head>
<body onload="go()">
</body>
</html>

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.
<?php
/**
 * Template Name: Hide Referrer
 */
require('./wp-blog-header.php');
?>
<!-- Hide Referrer Script Goes Here -->

Instructions

  • 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: http://your-domain.com/track/?url=http://google.com/