Trackback: A Guide for Implementing Trackback on Your Site

Trackback is a framework for communication between web sites. The primary purpose of trackback is for one site to notify another about a related resource, for example a link to a blog post. This is done through a technique generally known as a ping, which can be used for communication purposes other than tracking as well, notably to tell blog feed aggregators that a new post has been published.

While trackback is a standard feature of the main blog software platforms, an independent-minded webmaster should consider it a feature worth adding to any site. Communication between computers sounds daunting, but as always, thanks to some open source software, it’s really nothing that can’t be learned and implemented fairly quickly.

Trackback can be implemented either remotely, being integrated into your CMS or whatever script(s) you use to publish content, or it can be done via a dedicated script with a form used to specify the relevant attributes. It can also use either the POST method or the GET method, though I believe that some receiving computers choose to not accept GET method trackbacks.

It should also be mentioned that trackback is anonymous by construction. This means that it is used by a lot of spammers. Blog software platforms usually do a decent job of managing this spam, especially by using Akismet (reference the useful open source Akismet PHP Class), so that is something to consider as you develop your trackback functionality.

Generally speaking, there are five variables to consider when issuing a trackback:

  • trackback URI – sites that are setup to receive trackbacks usually publish a unique URI for each entry
  • title – the title of your referring resource
  • url – the location of your referring resource
  • excerpt – explanatory text to describe your resource; it could be the entire text of your posting or just a summary of it
  • blog-name – the name of the site where the resource you are referencing resides; note that this variable name illustrates how trackback traces its roots to the blog world

Implementing Trackback Functionality

There are two aspects to implementing trackback: the ability to issue a trackback and the ability to receive a trackback from others. For both, I use the PHP Trackback open source class, though I have made some modifications to enhance it which I will explain shortly.

Issuing Trackbacks

How you implement the ability to issue a trackback will depend on your specific situation, but for me, I like to use the auto_discovery function of the PHP Trackback class. This function will search any text you supply for links and it will then remotely open those links and search for trackback URI(s).

To illustrate, let’s assume you have a form to post a blog entry. For simplicity, let’s say that it includes fields for a title, a text description and for special notes or comments. You might assume that the title field will never include a reference to an external URL, but that the description and the notes fields very well may. In that case, you could write your form submission code such that you concatenate those two fields into one text variable, say $text, and then supply that variable to the auto_discovery function. It might look something like this:

Of course, if you prefer, you could add a field to your form for the trackback URI and manually enter it. In that case you wouldn’t use the auto_discovery function but rather you would just call the ping function directly using the manually entered URI. One thing to consider is that the auto_discovery function can take a fair amount of time and isn’t perfect so supplying a trackback URI manually may be better for some applications.

If you do choose to use the auto_discovery function, it’s useful to know that not all blog implementations list their trackback ping URIs in the same way. Most often, such URIs are specified via Resource Description Framework (RDF). However, sometimes they are merely listed in plain text or as a hypertext link. The current version of the PHP Trackback class only looks for URIs specified via RDF so to account for non-RDF situations, I modified the class. Specifically, I added code to look for URIs that are like %trackback.php% or %.trak%. The former are common for blogs made with WordPress and other PHP based blog platforms while the latter are used on the Microsoft Live Spaces blogs.

Receiving Trackbacks

If you want to issue trackbacks, it’s reasonable that you might also like to accept them, which turns out to be a more complicated proposition. Below I describe a basic system for doing this.

To begin with, I assume that we will want to keep track of people issuing trackbacks to our site, so I set up a MySQL table to do this. Here is relevant SQL code to create such a table:

You might notice that I have included a field, trackback_approved, which allows for basic moderation functionality. Given the rampant use of trackback for spamming, this is most definitely a good idea. You should notice also that it defaults to 1 which represents approved, unless it fails an Akismet spam check, which I have implemented. You can easily remove this Akismet feature or, if you want to use it, you’ll need to get a free API key. If you prefer to moderate each submission you should change the default to 0 and create your own system for reviewing and approving received trackbacks.

My basic implementation also checks to see if a trackback already exists to reject multiple requests. It could and probably should be improved to check for non-identical trackbacks that originate from the same source, assuming that X trackbacks in X seconds probably represents spam attempts. Finally, I provide for an email notice to be sent each time a trackback was received. You can easily modify or remove this feature.

Of course, keep in mind that I am only offering a way to handle trackback requests, but you will still need to add relevant trackback URIs on each of your website’s relevant pages. If you use the files I am making available, that will always be in the format: You will also probably want to add code to pull the trackbacks from the table we created above and show them on each relevant page.

Download Files

Below you can download a .zip file containing the following trackback implementation files:

  • akismet.class.php – this is a copy of Bret Kuhns open source class. It is used to perform the Akismet spam check.
  • db.php – this is a class from Justin Vincent I have used to setup a database connection. I don’t remember where I first found it and it may be an old or more bloated class than you need. Feel free to replace it with whatever equivalent you already are using.
  • test.php – this is a simple form that will let you specify relevant trackback fields to test out your trackback implementation.
  • trackback.php – this file is typically placed in the root directory and handles receiving trackbacks, as described above.
  • trackback.class.php – my modified version of the Ran Aroussi’s open source PHP Trackback class. Note: this was named trackback_cls.php originally.

Latest Version: 1.1 (2007-11-08) – improved the auto-discover function. If you rely on that feature then I recommend you upgrade…


Most of the download files are well commented. The main thing to consider are the include files. If you place all of them in the same directory you should be fine, but if you prefer to split them then make sure to adjust any relevant include statements to reflect the appropriate path locations. Generally speaking, at least the trackback.php file will be in the root directory.

For more information on trackbacks, read Teli Adlam’s useful WordPress Trackback Tutorial.

Like this content? Why not share it?
Share on FacebookTweet about this on TwitterGoogle+Share on LinkedInBuffer this pagePin on PinterestShare on Redditshare on TumblrShare on StumbleUpon

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.