PHP Redirect For Affiliates
by admin on 17/11/09 at 11:04 am
The problem: you, as a scurrilous affiliate marketer, have a website with a sales page pushing a particular product. People link to your page to get the product but your sales page then “sells them” again and links to the merchant’s website where they can actually get the product. Your website, in effect, is an obstacle in the purchase process! Your website’s sales page is perfect for visitors who arrive via search engines, and need to be persuaded to buy the product. However, for those visitors who have already made their buying decision when they reach your site (via “buy it now” links, for example), you really want to redirect them to the merchant’s site.
What we need is some simple PHP to do the following:
- Determine where our visitors come from.
- If they have come via the search engines, display our sales page page.
- If they haven’t come from the search engines, redirect to the merchant’s web page using our affiliate link.
Check out the code to do this. The code is ultra simple, but then it is meant for affiliate marketers to understand
$referrer = $_SERVER['HTTP_REFERER'];
$searchEngine = array('/search?', 'images.google.', 'search.', '/search/', '.yahoo.', 'del.icio.us/search');
foreach ($searchEngine as $source) {
if (strpos($referrer,$source)!==false) header( 'Location: http://www.merchant.com/click-123' );
}
This code goes right at the top of the page, even before the doctype and <html> element. It retrives the referrer and compares it with an array of search engine related URLs. If the referrer is not a search engine, the redirect to the merchant’s site is performed. If the referrer is a search engine, the web page defined after the PHP code is rendered.
This code makes the risky assumption that all links to your site are on pages that have already done the hard sell on the product.