Way back when, “link cloaking” referred to a Black Hat SEO technique (a way to get high rankings on search engines). I won’t go into the technical details, but basically the web page sends different information to the visitor based on who they are. In short, if the server detects that you are Googlebot (Google’s search indexing system which ranks content relevance) it displays “nice” information. This “nice” information would rank well, and consequently the site would be one of the first ones displayed in the search results). However, if the server detects that it is a human (i.e. you!), it displays “other” information (usually trying to sell you something). While an interesting topic in itself, that’s not what this post is about
Originally known as “affiliate link cloaking”, it has now replaced the Black Hat SEO technique as the assumed definition of “link cloaking”. As an example:
If you click on the links above, both will take you to www.google.com. But you’ll notice that the cloaked link doesn’t display the same information on the bottom-left of your browser.
There are many reasons why someone might want to cloak a link. The most common reason is for affiliate sales (where the affiliate gets a commission if they refer someone who ultimately makes a purchase). Under these circumstances, link cloaking does the following:
Anyway, without further ado, here is the code of my link.php file.
<?php $path = array( '123' => 'http://www.google.com' ); $key = htmlspecialchars($_GET['key']); if (array_key_exists($_GET['id'],$path)) header(’Location:’.$path[$_GET['id']]); ?>
Basically, this file compares the ID paramter (e.g. www.wandering.net/link.php?id=123) against the array. If a match exists (”123″ in this case), then it uses the PHP Header Location call to redirect the browser (”www.google.com” in this case).
To use, just change the HTML A (link code) from
<a href=”http://www.google.com”>This is an uncloaked link to Google</a>
to
<a href=”http://www.wandering.net/link.php?id=123″>This is a cloaked link to Google</a>
Simple