Trackback is a technology used by content publishing software like wordpress, movabletype, blogger etc to acknowledge url added in the commenting of post. The trackback acknowledge is sent using network ping from the originating site to receiving site. Let me demostrate how it works with a diagram shown below.

trackback.png

Trackback can also be used as a link building mechanism. Let me explain how it can be implemented using php. One php library is also there to do this. But now i am going to explain a simple mechanism in php. As i already explained it is done via ping method. The ping method is normal HTTP POST. The ping is sent to the trackback uri of the receiving post. The parameter required is url. The server will send a XML response for the comment. The XML response may be either a success result or a failure result with XML format response.

Success :

< ?xml version=”1.0″ encoding=”utf-8″?>
< response>
< error>0< /error>
< /response>

Failure:
< ?xml version=”1.0″ encoding=”utf-8″?>
< response>
< error>1< /error>
< message>Error message< /message>
< /response>

PHP implementation.

$params['http']['method'] = 'POST';

$params['http']['header'] = 'Content-Type:

    application/x-www-form-urlencoded';

$params['http']['content'] = "title=$title&url=$url&blog_name=$blog_name&excerpt=$excerpt";
Send the ping command with the parameters above and capture the result. 
The parameters should be URL encoded since we are using simple POST mechanism.

 //  Create the context from the formatted array

$context = stream_context_create($params);//  Open a stream to the url, save it in the pointer $fp

$fp = @fopen($trackback_uri, 'rb', false, $context);

//  Send the header and get the results, saved in $response

$response = @stream_get_contents($fp);

//  Always close for good measure

fclose($fp);

 What next is to parse the message whether its success or not ?
//  If this is true, there was no error

if (stripos($response, '<error>0</error>'))

    $outcome = "All clear! Trackback

        was sent successfully.";

else

    {

    //  Find the beginning and end of the message element

    $start_resp = stripos($response, '<message>');

    $end_resp = stripos($response, '</message>');    //  substr will return the actual message element, 

    //    with the tags included

    $outcome = substr($response, $start_resp,

        $end_resp - $start_resp - 1);

//  Replace the tags with blank space

    $outcome = str_replace('<message>', '', $outcome);

    $outcome = str_replace('</message>', '', $outcome);

    $outcome = "Error: " . $outcome;
     }//  Echo the results.  I formatted 'error' to be red.

echo "<p class='error>$outcome</p>";

Thanks to earn web cash for the php code

Click here to submit your review.


Submit your review
* Required Field

ABOUT THE AUTHOR:

Sanil S Founding member of MobMe Wireless Pvt Ltd, Ayruz Web Holdings

4 comments on “Trackback how to implement ?

  1. This is same as the working principle of an Echo Server. Right??

  2. pictures on said:

    How can I install the Plugin under WordPress 2.5

  3. Sanil S on said:

    Just copy the plugin in the plugin directory and Activate it in the Manage Plugin place.

  4. Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

Leave a Reply

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

*


2 + seven =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>