03Mar

Trackback how to implement ?

Web
Post Page Rank

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

Add to Del.cio.us RSS Feed Add to Technorati Favorites Stumble It!
   www.sajithmr.com

Random Posts

Monday, March 3rd, 2008 at 11:48 am and is filed under Web. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Comments so far.

  1. Posted by SAF on Monday 3rd March

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

  2. Posted by pictures on Friday 11th July

    How can I install the Plugin under Wordpress 2.5

  3. Posted by Sanil S on Friday 11th July

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

Leave a reply

Enter your email address:

Delivered by FeedBurner