Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryCookies and Browser Interaction

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

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.

  1. $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.

  2. $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"
    
  3. $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

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC