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:
- A blog “calling” and notifying a comment. The call is a “Ping”.
- A blog replying to the call and reporting whether the comment was noticed or not.
- 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:- Reception of ping and data sent with POST mode.
- Data check, if incorrect sends negative response in XML format and quits.
- If correct, processes data. If processing does not succeed, sends negative response in XML format and quits.
- 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"?>Negative response
< response>
< error>0< /error>
< /response>
< ?xml version="1.0" encoding="utf-8"?>As with parameters specs, the only two required variables are the ID sent with Get method and the field URL identifying the calling post.
< response>
< error>1< /error>
< message>Error message< /message>
< /response>
Model frame
Here an efficient script frame a bit extended:- Validity check of HTTP_GET_VARS['id'] and HTTP_POST_VARS['url'] fields.
- If they are not valid, a negative response in XML format ( see above) is sent.
- 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']
- If the save procedure does not succeed, a negative response in XML format is sent.
- If the save procedure succeeds, a positive response in XML format is eventually sent
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=452Frame 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