Niche Store Market
All Posts, Simple PHP

Simple URL Mask to Hide Affiliate Links

April 14, 2009 by Shane Isaacs · Leave a Comment 

Here is a neat little trick that is easy to do and will mask those ugly affiliate links. This method is a simplified version of what I had made when I created the Build a Niche Store v2 URL Masking Mod. You remember, it was the first url masking to be coded for Build a Niche Store and is surprisingly similar to what the developers ‘created’ and released months later in v3. What a Ko-inky-dink! This trick is for any link you want to mask, if anyone using BANS v2 wants to know how to incorporate this into their stores and mask all those eBay links just let me know and I’ll post the instructions.

This little program here simply hides all your affiliate links, pointing them back to your own site. When a user clicks on the link the program filters the correct response and sends them on to proper website with your affiliate link. There are many other ways to do this but I like this one because it only requires one file rather than making a seperate file with a redirect for every link. It is much more efficient and keeps the clutter down.

First open a new html document or notepad and save it as link.php.

You can name the file anything you want, just make sure you save it as a php file and change all the references below to whatever you named it. Some other popular names would be recommends.php, product.php, site.php and so on.

Second create a folder (directory) on your site (preferably in the root as it’s easier to remember). You can name this folder anything you want. I am going to call mine product.

Now we are ready to start creating some masks. I am going to use the following two links, one is a text link and one is a image ad.

Text Link: <a href=”http://www.phpbay.com/”>Make Money with eBay!</a>
Image Ad: <a href=”http://www.phpostock.com”><img src=”http://nichestoremarket.com/product/phpostock.jpg” alt=”Php O Stock” /></a>

Let’s open our link.php file now. First we need to add this code into it:

<?
$sku = $_REQUEST['name'];
if ($name == ”) {
$name = ($name);
header(“Location:”);
exit;
}
?>

I am going to mask the text link first which is for PhpBay. To do this I am going to add PhpBay to $name == like so:

<?
$sku = $_REQUEST['name'];
if ($name == ‘PhpBay’) {
$name = ($name);
header(“Location:”);
exit;
}
?>

Next lets add in the Location we want the link to point to:

<?
$sku = $_REQUEST['name'];
if ($name == ‘PhpBay’) {
$name = ($name);
header(“Location: http://www.phpbay.com/“);
exit;
}
?>

Finally we will ‘mask’ the url to point back to the new link.php file on our domain:

<a href=”http://nichestoremarket.com/product/link.php?name=PhpBay”>Make Money with eBay!</a>

That’s all there is to it. If we want to add another masked link, such as the image ad above, we just insert a second block of code, modified for our new ad, like this:

<?
$sku = $_REQUEST['name'];
if ($name == ‘PhpBay’) {
$name = ($name);
header(“Location: http://www.phpbay.com/”);
exit;
} else if ($name == ‘Php-O-Stock’) {     //notice we added the word else to this line!
$name = ($name);
header(“Location: http://www.phpostock.com/”);
exit;
}

?>

And then edit our ad link just like we did the text link:

<a href=”http://nichestoremarket.com/product/link.php?name=Php-O-Stock”><img src=”http://nichestoremarket.com/product/phpostock.jpg” alt=”Php O Stock” /></a>

If you want to add more products just copy the bolded code I showed you above and paste it in after the last bracket but before the question mark. Repeat that for every product you would like to add. Don’t forget to edit the $name and the Location for your new product though!

Here is a break down of how the code actually works:

$sku = $_REQUEST['name'];     // Requests the name= from the end of the url
if ($name == ”) {     // Looks if name= from the url is the same as $name
$name = ($name);     // Confirms that name= is equal to $name
header(“Location:”);     // Redirects to the correct url for that product
exit;     // Exits the code if redirect was completed
} else if     // If $name & name= did not match above, repeats for next product

Here are a couple very important things to remember!

<?
$sku = $_REQUEST['name'];
if ($name == ‘PhpBay‘) {
$name = ($name);
header(“Location: http://www.phpbay.com”);
exit;
}
?>

<a href=”http://nichestoremarket.com/product/link.php?name=PhpBay“>Make Money with eBay!</a>

The BOLD text MUST match exactly with no spaces between the single quotes!
The RED item must have a single space between Location: and http://

One you have made all your edits don’t forget to save your link.php file and upload it into the product folder we created. You can now place your new masked links anywhere on your site and they will redirect to the correct url. Make sure to TEST EVERY LINK!

Check out the two links below we just created. Hover over them to see that they point back to my site then click on them and watch them redirect. Just don’t forget to come back!

Text Link: Make Money with eBay!

Image Ad: Php O Stock

Copy the code below to your web site.
x 

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Niche Store Market