How to Hide a Referring URL with Javascript / PHP

Document Sample
How to Hide a Referring URL with Javascript / PHP Powered By Docstoc
					                                     Web Dev, Coding, Business and Life!




                     How To Hide A
                     Referring URL
   •   http://technerdia.com/1574_hide-referrer.html


    This simple little script hides the referring urls from one Website to another Website.

                                   View the Demo | Download Source

You 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.
    • Blackhat forums linking out to Websites / Services explaining something dirty. The script can be
      hosted on a remote domain so the original referring url 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.

<?php /** Hide the Original Referring URL of a link */

/** Location to redirect errors to */
$error_redirect = 'http://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>


Using the Hide Referrer Script
    • Line 3: Location to redirect errors, direct access hits and no URLs to.
    • Lines 8 & 9: Restrict the IP's that can access the script. To use, uncomment both lines and put your
      own IP address in. Replace 000.000.000.000 with your IP address.
    • Line 11: Gets the posted URL.
    • Line 12: If no $url is passed in, redirect due to error.
    • Line 14: If the URL does not contain http or https, display an error.
    • Lines 16-27: If no errors and the url is passed in, javascript redirects the user to passed in $url.


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

    • Copy the below sample to a file named: 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,
      and name the page something like: track, visitor, redirect, 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/

It is as simple as that... now, get busy masking those links before someone discovers your
secret admin area!



Have a comment? Find an error? Would you like to improve on this
script? Then shoot me some feedback! ~tribalNerd



               Follow techNerdia on Google+ | Follow Chris on Google+
                      Subscribe to techNerdia's RSS Feed
                          Copyright 2012 © techNerdia - All Rights Reserved
                                       http://techNerdia.com/

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:68
posted:9/25/2012
language:Unknown
pages:3
Description: Simple javascript / php script that hides the original referring url from analytic software.