How To Cloak Affiliate Links & Click Tracking With PHP

Here’s a sweet bit of code I found to not only cloak affiliate links with php, but also count the clicks:

Hiding Links With PHP and Counting Clicks with MySQL

The nice thing about this bit of code is that you can add an unlimited amount of links to the one file. I’ve set this up (5 minute job) and it works like a dream. If you know how to create a database, you’ll have this up and running lickety split.

I do a little bit of everything when it comes to link cloaking. I’ve used script programs (can be a bit clunky), .htaccess redirects, domain redirects, javascript methods (doesn’t work for non-javascript browsers), other bits & pieces of code. I’m really liking this code though so I’m going to give it a shot.


  • You don’t have to buy a link cloaker/click tracker for *each* domain. This is a free solution, simply install the script for each site if you like.
  • Redirects & tracks more than one link at a time.
  • You could also install this on one single domain and use it as your own personal tinyurl for all your sites. Potential problem with that idea: it will be easy to trace all the domains in your network.

To view your click counts, you just have to go into phpmyadmin, select the database, select the linkcount table and then browse–each link name and count is displayed.

If you want to prevent the search engines from spidering those links (does Google view affiliate links as paid links?), just block them in robots.txt with:

User-agent: *
Disallow: /redirect-filename-you-used.php

That is all it takes. From here you may want to write a front-end to display your click results or you could even display the count next to the specific link in your sites navigation menu to rank the most popular outgoing links.

Maybe if we harrass we can get him to whip up that front end too for us non-codeheads so we don’t have to dig around in phpmyadmin :P. If you use his code, why not drop him a comment or a link as thanks, it’s a keeper.

ETA: Patrick pulled through with some more code–wooohooo! You’ll find the code to view the stats here: Displaying Click Counts with PHP and MySQL. Works GREAT, a big thanks to!

Update: For WordPress users, there’s this handy plugin that will auto-cloak keywords that you set inside the WordPress admin panel (watch video to see how it works).

Bookmarks & Freebies Roundup Plus Updates


System Information for Windows
WP Plugin: Preview Site Themes Privately
WP Plugin: Feedburner Feed Stats
3 more GTD wallpapers! *Nice!
Download a …coffee replacement, really! *I’m scared to try it lol! Added
PPC Keyword Generator *Software
101 Essential Freelancing Resources *Tools, lots, don’t get lost 😉
Urban Fonts *Added
Turn Any Site’s RSS Feed into an Email
R|mail subscription widget

Good Stuff:

Free Chapter From Professional SEO With PHP!
The Article Marketing Experiment ($400/month with Clickbank)
One Way Inbound PR 9 Links For FREE
How to Make Money with Domains – Essential Resources for Beginners
A Comprehensive Guide to StumbleUpon: How to Build Massive Traffic to Your Website and Monetize it.
Paid Forum Posting – Worth it?
Positive and Negative Quality Ranking Factors from Google’s Blog Search (Patent Application)
Being Scraped? Here is Something You Can Do
The Ultimate WordPress Htaccess File?
Organize your pdf library with itunes

Pages Updated

Something I’ve wanted to do for awhile and finally got through tonight–I checked the links on the Affiliate Marketing Blogs page and cleaned out the links from blogs that are no longer online or updating. If I’ve removed your blog, it’s probably because it was offline when I checked. Just shoot me a note (with your url) and I’ll re-add it.

The page has a nice mix of blogs I think, everything from more chat based and newbie info to more advanced. However, I think it’s a little bare. If you have an affiliate marketing blog, let me know and I’ll check it out. I’m not interested in Internet Marketing blogs or blogs that mainly review or push products–just affiliate marketing please.

I’ve also updated and cleaned out the Webmaster Tools page. If you haven’t visited it in awhile, you may want to when you have some time. I’ve been reacquainted with some cool tools I forgot about while double checking the list ;).

A few graphics resources were added to the Freelance & Outsourcing page. It’s pretty bare too and if you have a service to offer, let me know.

Whew! All done, till next time ;).

ETA: Forgot to mention the forums were picked through as well and all the domains that were dead or hanging have been removed.

Bookmarks & Tools Roundup

Not a whole lot today, but here are some worthwhile tools, resources and posts that I’ve set aside to share with you. Many of these have been added to the appropriate bookmark pages here on SuperAff:

Ultimate htaccess File sample

Bookmark this page and check back frequently as updates to this file are made frequently (at least a few times a month), with only the very best tried-and-true htaccess examples.

Web 2.0 Colour Palette

Fonts 101

HTML Entities
*Includes Latin, Greek and others

*See what competitors are spending in adwords

The Catalog of Copyright Entries – Affiliate Marketing

Good Reading:

Busting Blog Ad Clutter

Business Blogging 101 – Measuring Your Blog’s Success

Contact Your Affiliate Managers

Free PHP MySQL Traffic Stats

Found a new (to me) web stats program to try. I’m needing something with more detailed stats to track growth and here’s what I’m loving so far: phpTrafficA – Web statistics made easy:

phpTrafficA is a GPL statistical tool for web traffic analysis, written in php and mySQL. It can track access counts to your website, search engines, keywords, and referrers that lead to you, operating systems, web browsers, visitor retention, path analysis, and a lot more!

One of the features I’m in love with is the keyword section, poke around in there and you’ll find the search engines listed with which keywords used. Nice!

ETA: Forgot to mention another sweet feature…You can look up a single day and see what keywords were used, which referrers sent traffic, what the popular pages were. Or view the stats for a single page, see what keywords are being used to find it, which search engine likes it, who’s sending traffic to it, sweet stuff!

You can also track multi-sites with this whether it’s on the same server or not (pixel tracking). If the sites are all on the same server, no pixel needed (nice!).

If you’re using this on a wordpress blog, just plunk the php code in the main index.php file.

I mentioned another one I really like some time ago: TraceWatch. You may want to give that one a shot too and see which one you prefer (good path analysis as well).

Swipe ‘Em – Bookmarks, Freebies & Resources

IP Domain Check
*This tool will find other domain names hosted on your IP address.

Free Font Manifesto

IP & DNS Tools

*Amberjack is a lightweight Open Source library, enabling webmasters to create cool site tours.

*swiped the above goodies from Peter Cooper’s Bookmarks

bbPress – WordPress forum

WordPress Comments.php Template

WP Plugin – Own The Feed (Dashboard)

*Convert your HTML and CSS based design into a WordPress blog theme

Webshots Pro
*Website Thumbnail Service

*Capture screenshots of (almost) any web page

Online File Browser

*This is a small php-script which provides a nice looking index of the content in the directory where it is located (including the directories below). **Upload one file and you’re good to go ;).

Spy on Your Competition with SpyFu
*Did you ever wonder who pays more for ads online MySpace or Turns out, it is Classmates by a landslide, but what about your competitors?

PayPal Button Creator
*Will increment the price by a fixed amount each minute from a starting price and either stopping at a fixed price or continuing indefinitely

Big List of CSS Tools

*Tracking the most popular of the most popular 😉

Alertra Spotcheck

SiteUptime Check
*Good for determining if the problem is your ISP or if it’s the webhost

Traffic Estimate
*Use the Traffic Estimate tool to find out approximately how much traffic a website gets.
*Provides free information for every site on the Internet including site traffic history and competitive analytics–Note this: alerting searchers to site profiles, promotional codes and trust scores for each search result displayed. Something to keep your eyes on ;).

*Drag & Drop Web Buttons

Daily Color Scheme

*Simple tool for creating shorter, human-readable links from long URLs. You install Shorty on your server, so the links you create with it never go away. Counts clicks as well. Perfect for aff links ;).

Crossword Puzzle Maker

Word Search Puzzle Maker

Big List of Online Generators

Users Manual Guide
*User Manual and User Guide for many equipments like mobile phones, photo cameras, monther board, monitors, software, tv, dvd, and othes..

Added to the affiliate marketing blogs bookmark page:

Affiliate Lesson

ETA: Also added a Competitive Analysis Tools section on the Bookmark Page

Swipe ‘Em – Freebies & Bookmarks

Pixie Color Picker
*Pixie is an easy-to-use, fast and tiny utility designed especially to fit the needs of Webmasters and Designers. Its a colour picker that includes a mouse tracker.

*GoogEdit makes it easier to manage Google AdWord Lists. Taking in a keywords list, it cleans it up for use in AdWords campaigns.

Dead Man’s Switch
*Dead Man’s Switch can protect or pass on your data and inform key persons of your untimely demise. You can set Dead Man’s Switch to perform a number of tasks if you don’t log on to your computer for a specified period of time. It can send out e-mail, encrypt or delete files, and post to web sites.

*AutoIt is a freeware Windows automation language. It can be used to script most simple Windows-based tasks (great for PC rollouts or home automation).

RSS Feed Button Tool

ASP eBay listing software
*By creating eBay listings related to the content using a simple ASP function call. Set up variables and call eBayDisplayItems function to create unique eBay listing choosing the correct keywords and searching category. This eBay listing software works in any ASP hosting with XML object installed.

Added to the SuperAff’s Bookmarked Tools page:

Color Scheme Generator
Easy RGB
Netmechanic’s Graphic Cruncher
Dingbat Pages
Google Keyword Metrics Tool
Searchspell Typos
SEObook Keyword Suggestion Tool
Apogee Keyword Research Tool

The Tools page was also re-organized a bit, with the color tools and css resources moved into their own sections.

Added the Blogger Forum to the main Bookmark Page.