Trackback PHP Programming, How To Guide

How to connect your site to other blogs through cross posting integration

Trackback is a system introduced by Movable Type to allow the connection between different post blogs. This cross-posting technique has put in contact all the blogs supporting the feature, playing an important role in the exponential growth this self publishing tool has experienced over the last few years.

The mechanism is straightforward: blogs that accept “replies” to their post from external posts as well, provide a unique identifier to each post called trackback URL. When a user posts in reply or with regard to news read somewhere else, he/she will do it including in the post the trackback URL of the news in question.

Therefore, interventions on two blogs will be reciprocally linked: on one of them will appear the trackback URL (something like “ I am talking about the article read here”) while on the other one the reply notice ( like “hey, someone replied from this address”) Track back procedure consists then in two steps:

  1. A blog “calling” and notifying a comment. The call is a “Ping”.
  2. A blog replying to the call and reporting whether the comment was noticed or not.
A large number of platforms have trackback management integrated as a default, but in the net there are many informative systems developed ad hoc (such as Ikaro.net). For those systems trackback management has to be developed manually. The features which can be implemented in a custom self publishing system are two. System can be enabled to:
  • Accept replies from external blogs (receiving pings)
  • Reply to external blogs (sending pings)

Trackback URL

Let‘s see for the moment to put our blog in listening, in order to detect if somewhere in the net news or articles appeared on our site are being referred to. Let’s then manage ping requests. Technically, a ping is a call to a script with a post method, through which both POST and GET variables are sent. This script will be the trackback URL. The script data flow is the following:
  1. Reception of ping and data sent with POST mode.
  2. Data check, if incorrect sends negative response in XML format and quits.
  3. If correct, processes data. If processing does not succeed, sends negative response in XML format and quits.
  4. Sends positive response in XML format.

Data specifics

Let us examine the parameters sent by the pings managed in the script:
  • GET method 1.Unique post ID the caller is replying to -required
  • POST method 1. url > unique URL containing reply to post - required 2. blog_name > name of external blog - optional 3. title > reply title - optional 4. excerpt > reply text - optional

Reply specifics

Responses to pings, both positive and negative, have to be sent in XML format. So the script has to send the proper header ("Content-Type: text/xml") before any other source output. Positive response:
< ?xml version="1.0" encoding="utf-8"?>
    < response>
        < error>0< /error>
    < /response>
Negative response
< ?xml version="1.0" encoding="utf-8"?>
    < response>
        < error>1< /error>
        < message>Error message< /message>
    < /response>
As with parameters specs, the only two required variables are the ID sent with Get method and the field URL identifying the calling post.

Model frame

Here an efficient script frame a bit extended:
  1. Validity check of HTTP_GET_VARS['id'] and HTTP_POST_VARS['url'] fields.
  2. If they are not valid, a negative response in XML format ( see above) is sent.
  3. If they are valid, the reply stored in POST blog_name, title, excerpt variables is saved and connected to the proper post through HTTP_GET_VARS['id']
  4. If the save procedure does not succeed, a negative response in XML format is sent.
  5. If the save procedure succeeds, a positive response in XML format is eventually sent
Step 3 is strictly linked to the way the informative system manages data. If information is stored on a database, it will be necessary to insert data in the response table specifying as key the reference post ID sent with Get method. If instead responses are managed on XML or ASCII text files, they will have to be stored according to the specs of the system in use.

Trackback URL

Once the script has been developed and stored, this will be used to provide the trackback URL of any post of your blog. Let us suppose the script has http://your.blog.it/cgi/trackback.cgi as an URL, the URL to supply to your visitors for the article whose id is 452, would be for instance http://your.blog.it/cgi/trackback.cgi?id=452

Frame of source code to modify

Here follows the screenshot of a php source code frame you can customize according to your needs..
< ?php
function send_error($msg) {
                header ("Content-type: text/xml");
                print "\n";
                print "< response>< error>1< /error>< message>$msg< /message>< /response>";
                exit;
                }
if (!$HTTP_GET_VARS['id']) {send_error("TrackBack ID missing");}

if (!$HTTP_POST_VARS['url']) {send_error("URL missing"); }

if (!$HTTP_POST_VARS['title']) {send_error("Title missing");}

if (!$HTTP_POST_VARS['excerpt']) {send_error("Body missing");}

if (!$HTTP_POST_VARS['blog_name']) {send_error("Blog name missing");}

// SAVE DATA INTO YOUR COMMENT SECTION HERE

header ("Content-type: text/xml");
print "\n";
print "
< response>< error>0< /error>< /response>";
exit; ?>

Daniele Di Gregorio


12.05.2006 Online Marketing

links Links

Syndacate Feed

Feedburner Technorati

Send me updates by email:




Creative Commons License
This work is licensed
under a Creative Commons 3.0 License.

English  Portoguese