Affiliate Code Removed From Browser URL
Some people dislike buying from affiliate links. Justifications vary, but the fact remains.
They might decide not to buy if they arrive at a merchant's website and see what looks like an affiliate URL in their browser's address bar.
Today, I'll describe how to remove the affiliate code from the browser's address bar.
The code to remove the affiliate information from the URL needs to be done by someone who is authorized to update the landing page source code. In other words, site owners who want to save those sales.
The code sets a cookie you can customize. Then it redirects to the same page without any URL parameter information. (URL parameter information is the "?" in the URL and the data following it.)
Here is an example URL with parameter information and the way it will look in the browser's address bar when this system is properly installed.
http://example.com/widget?aff=ABC123 http://example.com/widget
Thus, the affiliate cookie is set and the potential buyer doesn't see affiliate code information in the URL of their browser.
To implement, put this PHP code at the top of the source code of the landing page, above any HTML code. (Customization notes follow.)
<?php if( count($_GET) ) { $CookieName = "Name_of_cookie"; $CookieValue = "whatever value you want"; $CookieValueDays = 12; setcookie($CookieName,$CookieValue,time()+intval($CookieValueDays*24*60*60),'/'); header("Location: {$_SERVER['PHP_SELF']}"); exit; } ?>
Customization:
There are three places to customize in the above PHP code. All have to do with setting a cookie.
-
$CookieName = "Name_of_cookie";
Replace
Name_of_cookie
with a name for your cookie. Generally, the name would be the name expected by your affiliate software, assuming you're running such.The cookie name needs to start with a letter and may be composed of letters, numbers, and underline characters.
-
$CookieValue = "whatever value you want";
Replace
whatever value you want
with the value expected by your affiliate software. Any value should work here.If the value includes double-quote marks (") or backslash characters (\), they will need to be escaped with a preceding backslash. This example shows before and after escaping:
"The "sweet" outlook \on life" "The \"sweet\" outlook \\on life"
-
$CookieValueDays = 12;
Replace
12
with the number of days the cookie shall last. Decimal numbers are acceptable. (0.01666667 is 1 minute and 0.08333333 is 5 minutes.) Some browsers are likely to disallow cookies that last over 10 years (3652.5 days), because that was stated in the original Netscape cookie specification. So consider 3652.5 days the maximum.
Put the PHP code at the top of a test page and try it out. Verify all parameters are removed from the URL in the browser window and that a cookie is set.
The Cookie Dump Tool can make checking cookies a lot easier.
When you go live, your affiliates won't have their affiliate code displayed in the browser's address bar. And the cookie will still be set.
(This article first appeared in Possibilities newsletter.)
Will Bontrager