Hiding Affiliate Links With PHP

January 16, 2009 · 98 Views · Filed Under Scripts 

While I was working on a new layout for my main site, I thought about implementing a system of “hiding” affiliate links and making them appear cleaner.

So, instead of this:

http://secure.hostgator.com/cgi-bin/affiliates/clickthru.cgi?id=bigfish

I wanted something like this:

http://www.0092ff.com/go.php?id=hostgator

I found a ton of scripts that would allow me to do this, both free and paid versions, but I couldn’t find exactly what I wanted. I tested out a couple free scripts, but I didn’t like the way the links were created.

After a while I stumbled upon this simple PHP code that would allow me to do exactly what I wanted to do, without all the bells and whistles.

Create a text file and copy/paste the following code:

<?php
  $id = $_GET['id'];
  $links = array(
    "google" => "http://google.com",
    "yahoo" => "http://yahoo.com",
    "wikipedia" => "http://wikipedia.org"
    );
 
  header("Location:".$links[$id]);
  exit;
?>

Then, just change the names and link codes to fit your needs. Save the file as “go.php” and then set up your links like this:

http://www.yourdomain.com/go.php?id=google

http://www.yourdomain.com/go.php?id=yahoo

http://www.yourdomain.com/go.php?id=wikipedia

If you want to add more links, just copy/paste another line in. You have to pay attention to where your commas are placed though.

It doesn’t get any easier than that!

Comments

Leave a Reply