Hiding referral links

Posted on June 12th, 2008 by dandavis
Tags:

When you run across a referral link to a product (at Amazon.com, for example), are you the kind of user that copies the link and replaces the referral code with your own or a friends?

Yeah, me too! I hate users like us!

There might be packages or code snippets out there for this already, but I wrote my own 'cause that's what I do.

First, I wrote a file (externallinks.php) that has a list of referral links… this could be done in a database, but that was overkill for me.

<?php
$url['amazon-product-1'] = 'http://www.amazon.com/exec/obidos/ASIN/B0015AR7AK/dandaviscom-20';
$url['amazon-product-2'] = 'http://www.amazon.com/exec/obidos/ASIN/1591862027/dandaviscom-20';
# Not sure if this next one works like I think it does…
# but it's a whole lot shorter than the one that I *know* works.
$url['default'] = 'http://www.amazon.com/?tag=dandaviscom-20'];
?>

Once you have your list of external links, you would setup your external.php (or whatever you want to call it)…

<?php
require_once('externallinks.php');
if (isset($_REQUEST['link']) && !empty($_REQUEST['link'])) {
   $link = $_REQUEST['link'];
   if (isset($url[$link]) && !empty($url[$link])) {
      Header('Location: '.$url[$link]); exit;
   }
}
echo 'Give the user some error about there not being a valid link. You know… to be helpful and all…';
exit;
?>

Now, in your pages, instead of putting in the direct links, you can link to this page.

For example, instead of:

http://www.amazon.com/exec/obidos/ASIN/B0015AR7AK/dandaviscom-20

You would link to:

http://yourdoamin.com/external.php?link=amazon-product-1

Now, once the user gets to Amazon (or wherever), then they could change the referral code… unless that site uses some sort of redirector. Amazon.com has one: http://www.amazon.com/gp/redirect.html.

Post a comment

You must be logged in to post a comment.