Affiliate Links for Non-Product Pages
Our affiliates can link to any page of any of our web sites
and have their affiliate cookie set.
I'll tell you how it's done. Maybe you'll find a use for
something similar.
For affiliates, it's just link and go.
Implementing the mechanism wasn't so straightforward. It had
to take into account:
-
Cookies can be set only by the domain that will read
them. Domain flowto.info can not set a cookie for
domain bontragercgi.com
-
Cookies need to be set for affiliate programs on two
separate domains.
-
Web pages on many domains may be linked to.
The solution we chose is implemented as a redirect page. The
redirect page causes cookies to be set and then redirects
the browser to the correct destination.
I'll tell you how it works from the site user point of view,
the affiliate point of view, and the function implementation
point of view.
Site User Point of View
The site user clicks on a link.
The browser is taken to a page that sets some cookies. Then
the browser is redirected to the destination intended for
the link.
Affiliate Point of View
Here is the format of the link URL to set your affiliate
cookies and redirect your site user's browser to the correct
destination:
Replace _A_ with your affiliate ID and replace _URL_ with
the destination URL. Example (assuming "XXXX" for the
affiliate ID):
The above example would send the visitor's browser to
page.php, which sets two affiliate cookies for affiliate ID
XXXX, one for the bontragercgi.com affiliate program and one
for the willmaster.com affiliate program. Then, the browser
would be redirected to http://flowto.info/
Click here
for a demonstration.
As another example, you could let your site visitors email
me, the Master Series programmer, directly and set your
affiliate cookie at the same time. Simply use my
harvest-proof email link as the destination URL.
Here is copy n' paste code (replace XXXX with your own affiliate ID):
Click here
for a demonstration of the above.
It's not as fast as some redirects it first retrieves an
image from each domain. The image mechanism checks for valid
affiliate ID before setting the cookie.
Any direct software purchases then or later using a browser
with that cookie results in a commission.
The redirect affiliate link can be cloaked. A generator to
generate the onmouseover/onmouseout attributes for cloaking is
at the "Link Cloak Code Generator" blog post.
Function Implementation Point of View
Below is the source code of the redirecting page.php web
page. You may wish to copy it from the text box and paste it
into a word processor so it's readily available for
reference.
What the PHP Section Does
The PHP code must be at the top of the file. No spaces or
blank lines may precede it.
First, the PHP sets the values representing the affiliate
code and destination URL to blank. Then, it proceeds to
extract any affiliate code/destination URL information from
the URL in the browser's address bar.
You'll notice a list of domain names for the $AllowedDomains
array.
Domain friendsofpineridgereservation.org in that list is not
our domain, but the domain of a special charity. Thus, we
let affiliates set an affiliate cookie if they link to that
domain through this system.
Replace our domain names with the domain names you want to allow
redirects to. Note that the line of all but the last domain
name ends with a comma.
The domains on the list must be all lower-case.
Do not use www. in front of the domain names. You can,
however, specify other sub-domains.
Below the list of domains is where the PHP validates that
the domain name of the destination URL is on the list. If it
is not, the values representing the affiliate code and
destination URL are set back to blank.
If either of the affiliate code/destination URL values are
blank, the browser is redirected to the location specified
in the header() function call. Replace the
/master/ URL in the header()
function call with your own default URL.
What the Web Page Source Code Section Does
Below the PHP code section is where the web page source code
starts.
Within the source code, PHP can insert values. The code
<?=$dest?> inserts the destination URL and the code
<?=$affcode?> inserts the affiliate ID.
In the HEAD area is a META tag to refresh the page with a
different URL as soon as the page has finished loading. The
URL is inserted with PHP.
In the BODY area, you'll find two image tags. One of the
image tags gets an image from a script at willmaster.com and
the other from a script at bontragercgi.com. The URLs of the
images include the affiliate ID as inserted with the <?=$dest?> PHP code.
Both scripts linked to from the image tags check to verify
the affiliate ID is in the database and, if yes, set a
cookie. Whether or not a cookie is set, the scripts return an
image for the browser. (In this case, the images are clear
GIFs.)
Below the image tags is JavaScript to present a delayed
"click here" link and a similar link for non-JavaScript
browsers.
When the web page has fully loaded (including both images),
the meta tag redirects the browser to the destination URL as
found in the browser's address bar.
Other Uses
The above might be modified for pretty much any need to set a
cookie on browsers clicking on certain links.
If not for an affiliate program, it might be a function of
an outbound link click tracking system, for example, to spot
when visitors return. Or it might serve to set the cookie
that records the pages site visitors view, in the order they
view them.
Undoubtedly, you'll recognize it when you need functionality
this code can help with.
Question:
Did you find this article interesting and understandable? How can it be improved?
Your response is anonymous.
When done typing, click anywhere outside the box. [more info]
Will Bontrager
©Copyright 2007 Bontrager Connection, LLC Bontrager Connection, LLC
Please note:
Articles on this website are presented "as is". However -
If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Ask one of our Experts and you'll have your answer!
Click here for details.