Poplink: Track Click Pings with PHP and MySQL

Poplink is a PHP class library that tracks click pings, a new browser capability proposed for HTML by the WHAT Working Group that is currently being tested in development builds of Mozilla Firefox.

A click ping is a request sent by a browser to a web server that tracks a click on an outgoing link. A new (and unofficial) ping attribute to the HTML a tag identifies one or more URLs that should be pinged when a link is clicked:

<a href="http://ekzemplo.com" ping="http://drudge.com/receive-click-ping.php?

In the preceding HTML markup, because the Ekzemplo link has a ping attribute, a browser that supports click pings will request the ping link after loading the linked page.

Click tracking is common on web sites, implemented through browser redirects that interpose a script between the original page and the linked page. The click ping adds support for this process to HTML.

The Poplink class demonstrates how to receive and track click pings using PHP and MySQL.

Version 0.1.


This software was developed by Rogers Cadenhead, publisher of the Workbench weblog. It has been released under the GNU General Public License.

  • PHP
  • MySQL

I'm running the software on PHP 4.3.2 and MySQL 4.0.2. I think it should work with version 4.0 or higher of both PHP and MySQL, but that's only a guess.

Installation instructions
  • Download the Poplink archive in either tar.gz or zip format and unpack the archive.

  • Save the PHP class library poplink_core.php in a directory where it will be accessible to PHP web pages. I put it in the software's include_path directory, which is often /usr/local/lib/php on new installations.

  • Save the other three PHP pages in a web directory where you'd like to receive click pings and track the results.

  • Load your copy of report-click-pings.php with a browser to create the MySQL database table that holds click ping data.

An example use of this class is demonstrated by the report-click-pings.php script. An expanded version of this script is used on the popular links report of the Drudge Retort.

Poplink employs the following variables, which must be defined in poplink.php:

  • $database_server, the host name or IP address of the MySQL database server that holds click ping data

  • $database_name, the name of the MySQL database

  • $database_user, a user who has access to this database

  • $database_password, the user's password

The following constructor and methods are available:

  • Poplink(): Create a Poplink object

  • get_link($url): Retrieve data associated with a click ping's URL, creating a new record if the URL has never been pinged before. Returns false if the data cannot be read.

  • get_popular_links($limit = 100): Get an array containing the $limit most popular links ranked by number of clicks. Returns false if the data cannot be read.
Version History

  • Version 0.1: Original release, Jan. 20, 2006

Copyright 2006 Rogers Cadenhead

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.