Cloak And Rotate Your Affiliate Links!

Here’s a simple php script that you can use to not only cloak the referrer information, but also to rotate through your affiliate links so that you can test different offers and/or different advertising networks.

In order to hide your traffic sources you need to send the user through a double-redirect before pushing them along to the advertisers page. This can be done many different ways, but for the sake of this post I’m just going to use a very basic PHP redirect. For this setup, have the offer link on your landing page point to link.php, which will immediately redirect them to offer.php. Once they reach offer.php it will randomly select one of the affiliate links and redirect them on to their final destination. It’s that simple.

link.php

<?php
/* Redirect browser */
header("Location: offer.php");
/* Now the next line just makes sure that code below does not get executed when we redirect. */
exit;
?>

Now here’s the second file – You’ll want to replace the URL’s with YOUR affiliate links. If you’d like to add or remove offers just add or remove one of the “$affiliateoffer[] = ‘http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=1788&t202kw='” lines.

offer.php

<?php
$r = $_GET['sub'];
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=1788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=2788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=3788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=4788&t202kw=';
$affiliateoffer[] = 'http://www.yourdomain.com/tracking202/redirect/dl.php?t202id=5788&t202kw=';
srand ((double) microtime() * 1000000);
$random_number = rand(0,count($affiliateoffer)-1);
$dur = ($affiliateoffer[$random_number]);
$moneysite = $dur.$r;
header("Location: $moneysite");
?>

There you go, now you’re safeguarding your leads as well as testing out networks/offers. Remember, the secret to having sustainable campaigns is to always be testing!

2 thoughts on “Cloak And Rotate Your Affiliate Links!

  1. Excellent script, combining both referrer cloaking and offer rotation in one.

    I like to use the function mt_rand() instead of rand(), as it is (supposedly) faster and more “random”, and does not need to be seeded with srand().

    I also saw someone using a new function for this type of thing that I hadn’t seen before, array_rand() . According to PHP.net, it will “Pick one or more random entries out of an array”

    Lines 8-11 of offer.php now become:

    $moneysite = $affiliateoffer[array_rand($affiliateoffer)].$r;

    Note that array_rand() returns a key to the array, not the value itself.

Comments are closed.