PHP Code For Creating ClickBank Tracking IDs

My last posting about using a central script to generate unique ClickBank tracking IDs has elicited a number of comments and emails from readers looking for more information about how to do it without shelling out $997 (actually, $1497 if you don't want to use his hosting system) to the Rich Jerk. So I did some digging around and found something that'll really help you get started on this.

It's Base 36!

Remember how I said that a tracking ID consists of numeric digits and uppercase characters, giving you 36 possible choices (0 to 9 plus A to Z) for each character in the ID? If you remember your math, you'll recognize that this is a “base 36″ system where the numbers go 0, 1, 2, … 8, 9, A, B, C, …, X, Y, Z, 10, 11, 12, … 18, 19, 1A, 1B, …, 1Y, 1Z, 20, etc. You may have seen numbers like this before, because geeks often talk in “base 16″ or “hexadecimal”, which is like base 36 except that only the 6 letters from A to F are used.

So to generate a ClickBank tracking ID all you need is to keep an integer value around, add 1 to it whenever you need a new tracking ID, and then convert that number to base 36. You can even go the other way by converting a tracking ID from base 36 to base 10 (our standard decimal system for counting by 10) to get back the original integer value — very handy for storing something in a database! (Hint for the database geeks: use an auto-increment integer primary key.)

Converting to Base 36 with PHP

Converting to base 36 is not something you find in most code libraries, but I figured that a quick search for a PHP routine to convert an integer to a hexadecimal (base 16) value would be a starting point for my base 36 conversion routine. Then I came across this little gem, written almost four years ago:

A Binary-Octal-Decimal-Hexadecimal-Base36 converter

That's right, someone's already written a base 36 converter for us! You can actually try it out online. Enter a number like 845623 in the Decimal (input) field and press the DEC to B36 button near the bottom of the page to convert it to its base 36 representation, I4HJ. Press the B36 to DEC button to go the opposite way, from base 16 to decimal. If you're looking for a simple way to manually generate some ClickBank tracking IDs, this is a nice little tool to do it.

The source code for the converter is available and is distributed under an open source license, so if you plan on creating a script for sale, you should come up with your own version of the converter. But for personal use this is a great place to start.

Note that you don't have to use a database to store the data your script collects, but given how easily PHP interfaces with MySQL it's probably the wisest choice. But if you don't get a lot of traffic through your affiliate script then you could get by storing things in files, too.

Sponsored Link: Learn how to get AdWords clicks for less than one cent using the simple technique
described in AdWords180.

Eric Giguere is the author of Uncommon AdSense and the award-nominated (that just means it lost!) blog Make Easy Money with Google and AdSense.

Socialize This Post (Please!)

Add to OnlywireAdd to Onlywire

Tags

Comments

Comments are closed.

Subscribe without commenting