You will notice in many blogs, in the comments section, many comments like this: Pingback from …. What is a pingback and how it differs from regular comments even if they are listed in same section?
I pingback is a pat on the shoulder from one blog to another where first says: Hey, psssst, blog! I mentioned you in a post, care to mention me back? The second blog may choose to post a comment (pingback comment) where it will take the title and a little excerpt from the first blog. The pinback specification can be found here but it's lame and explains nothing technical!
As I built my custom blog engine I wanted to integrate pingback. Pingback relies on XMLRPC and you can read more here and here! I'll explain the concept in a nutshell: XMLRPC allows one to send commands in XML to a remote script by using HTTP POST and have it execute stuff! This is how pingback works. You send a command to the rpc client in the blog and the blog will choose the further steps.
These are the steps you have to take:
Step1: Load the page you link to and discover any RPC client. In the HTTP header will look like this:
X-Pingback: http://example.com/pingback/xmlrpc
and in the HTML body it will look like this:
<link rel="pingback" href="http://example.com/pingback/xmlrpc" />
Step2: Notify the XMLRPC server of your link by sending a RPC pingback command.
Step3: Pray it'll pass moderation and appear in the blog :)
Warning: This is not a good link spam method unless you have some real content and the pingback passes moderation.
I downloaded WordPress and the code inside is really not my type! Not clean and nice formatted as I enjoy PHP scripts. I have no time to see how WordPress works, I'd rather rebuild it myself! So … I kept looking and finally got to the solution I needed which is a two step trick. You have to autodiscover the RPC client and issue the command.
Below is the PHP script which relies on the XMLRPC integrated in PHP. I might make it standalone but I wrote this code yesterday. This code needs PHP cUrl Class previously declared!
<?
//---------------------------------------------------
// This is the autodiscovery of XMLRPC client. Can be used alone.
function findXmlRpc($target){
$hc=new eHttpClient(); $hc->get($target,0,1); $hdr = $hc->getHeader();
return (isset($hdr['X-Pingback']) ? $hdr['X-Pingback'] : false);
}
//---------------------------------------------------
// Change $returnbool to 0 to get exact XMLRPC response and error codes
function pingBack($target,$source,$returnbool=1){
$xmlrpc = findXmlRpc($target);
if($xmlrpc === false) return false;
$request = xmlrpc_encode_request("pingback.ping", array($source,$target));
$http_info = array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request
);
$context = stream_context_create(array('http' => $http_info));
$file = file_get_contents($xmlrpc, false, $context);
$response = xmlrpc_decode($file);
if($returnbool) return (xmlrpc_is_fault($response) ? false : true);
if(xmlrpc_is_fault($response))
return array($response['faultString'],$response['faultCode']);
return $response;
}
//---------------------------------------------------
?>
<?
$success=pingBack("http://www.theblogyoulinkto.com/page","http://www.theblogyoulinkfrom.com/page");
?>
Easy right? It took me over 2 hours to find specs to get this done as I love to reinvent the better wheel :) N-Joy!
Post Feedback