Copyright
© Groundbreak.com. All rights reserved.
Any comments, suggestions, or mistakes: smiles@groundbreak.com
|
Printing
the affiliate ID on a web page or in an order button
The affiliate cookie
contains the username of the referring affiliate - so, by
using javascript or php to fetch this cookie the ONLY info
you will be able to print out is the affiliate username.
Javascript
Between
the <head></head> tags in your HTML page you
will place this javscript:
<script>
<!--
function ReadCookie(cookieName) {
var theCookie=""+document.cookie;
var ind=theCookie.indexOf(cookieName);
if (ind==-1 || cookieName=="") return "";
var ind1=theCookie.indexOf(';',ind);
if (ind1==-1) ind1=theCookie.length;
return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
-->
</script>
Then,
anywhere in your HTML document you can reference this
code to fetch the affiliate's username and print it to
the screen:
<script>
<!--
document.write("This visitor was referred by: "
+ ReadCookie('COOKIENAME'));
-->
</script>
In
the tag above, you need to replace
COOKIENAME with the actual name
of the affiliate cookie you have set in the affiliate
program administration page. The above tag will print
out:
This
visitor was referred by: AFFILIATE
in
the HTML of your web page. If there is no referring affiliate,
it will still print out:
This
visitor was referred by:
So,
you can add some additional code to only print out the
text if the affiliate cookie is present:
<script>
<!--
if (ReadCookie('COOKIENAME'))
{
document.write("This visitor was referred by: "
+ ReadCookie('COOKIENAME'));
}
-->
</script>
and
the text will only be printed out if there is a cookie
set.
PHP
If
you're using a php script (instead of a .html or .htm
file, you just change the file extention to .php) you
can insert the cookie by using the following code:
<?
if (isset($COOKIENAME)) {
echo $COOKIENAME;
}
?>
and
the referring affiliate's username will be printed to
the page.
|