Follow @XavierMedia at Twitter.com

Xavier Media® Tools and tips for webmasters and bloggers

  Subscribe via email

  Subscribe via RSS
  What is RSS?

  Follow @XavierMedia

  Join our community

XavierMedia.com

Webmaster Tools

Keywords

Recent Posts

Blogs

RSS iPhone and iPad stuff – Most Useful Things

Photo by AndreasBylund.com

How to hide your affiliate links – part 4

August 14th, 2009 by Andreas from Xavier Media®

In the last part we had a look at how to redirect users to your affiliate links using a Javascript in an external file. Now it's time to create something similar in PHP.

Affiliate link redirection in PHP

This is working in a similar way as the last Javascript we created to redirect users to your affiliate links. So first we need to create a text file called linking.php (this example requires that your web host got PHP installed) and copy the following code into it:

<?php

$links = array(
"xavier" => "http://www.xaviermedia.com/",
"sample" => "http://www.sampleaddress.com/",
"blog" => "http://blog.sampleaddress.com/"
);

if ($links[$_REQUEST[link]] != "") {

Header("Location: ". $links[$_REQUEST[link]]);

} else {

Header("Location: http://". $_SERVER[HTTP_HOST]);

}

?>

As in the Javascript example you replace the blue links with your own links, but one advantage with this example is that you can give each link an easy to remember name like xavier, or sample. You can of course add as many links as you like by just adding more lines.

Once you've uploaded this file to your web server you can create links like this:

<A HREF="http://www.sampleaddress.com/linking.php?link=xavier">Text</A>

The following example would redirect a user to www.xaviermedia.com.

If a link is not found in the file users would be redirected to your own web site instead of getting errors. You can of course change this to redirect the users to any page you like by replacing the following code in the PHP file:

Header("Location: http://". $_SERVER[HTTP_HOST]);

To for example redirect users to www.sampleaddress.com/link_not_found.html you would replace the above line with this code:

Header("Location: http://www.sampleaddress.com/link_not_found.html");

If you're a hosting customer at eXavier.com we can create the PHP file for you completely free of charge. Just let us know the links you want included in the script and we'll send you the file :D

You may also be interested in...
How to hide your affiliate links – part 3
How to hide your affiliate links – part 1
How to hide your affiliate links – part 2

Subscribe to new posts from this blog

Leave a Reply

RSS 24/7 Webmaster

RSS Adv.erti.se

RSS Public Information

RSS XavierMedia.org

© Copyright 1996-2010 Xavier Media®. All rights reservered.
Contact us | Support/help | Privacy Policy | Company Info
The World According to Xavier | Domain Names