Sending a pingback using the PHP CURL module
To send pingbacks from your site to other blogs/communities/etc., you can use the PHP CURL module:
<?
function send_pingback($sourceURI, $targetURI)
{
$target = file_get_contents($targetURI);
// HTTP headers are now in $http_response_header, see docs of HTTP wrapper
foreach ($http_response_header as $header)
if (preg_match("/^X-Pingback:\s*([^\s]+)\s*$/", $header, $matches))
$serverURI = $matches[1];
if (!$serverURI) {
$target = html_entity_decode($target);
if (preg_match("/<link rel=\"pingback\" href=\"([^\"]+)\" ?\/?>/", $target, $matches))
$serverURI = $matches[1];
}
if (!$serverURI)
return;
$xml = ‘<?xml version="1.0"?><methodCall><methodName>pingback.ping</methodName><params>’.
‘<param><value><string>’.$sourceURI.‘</string></value></param>’.
‘<param><value><string>’.$targetURI.‘</string></value></param>’.
‘</params></methodCall>’;
$rq = curl_init();
curl_setopt($rq, CURLOPT_URL, $serverURI);
curl_setopt($rq, CURLOPT_POST, 1);
curl_setopt($rq, CURLOPT_POSTFIELDS, $xml);
curl_exec($rq);
curl_close($rq);
}
send_pingback("… source uri …", "… target uri …");
function send_pingback($sourceURI, $targetURI)
{
$target = file_get_contents($targetURI);
// HTTP headers are now in $http_response_header, see docs of HTTP wrapper
foreach ($http_response_header as $header)
if (preg_match("/^X-Pingback:\s*([^\s]+)\s*$/", $header, $matches))
$serverURI = $matches[1];
if (!$serverURI) {
$target = html_entity_decode($target);
if (preg_match("/<link rel=\"pingback\" href=\"([^\"]+)\" ?\/?>/", $target, $matches))
$serverURI = $matches[1];
}
if (!$serverURI)
return;
$xml = ‘<?xml version="1.0"?><methodCall><methodName>pingback.ping</methodName><params>’.
‘<param><value><string>’.$sourceURI.‘</string></value></param>’.
‘<param><value><string>’.$targetURI.‘</string></value></param>’.
‘</params></methodCall>’;
$rq = curl_init();
curl_setopt($rq, CURLOPT_URL, $serverURI);
curl_setopt($rq, CURLOPT_POST, 1);
curl_setopt($rq, CURLOPT_POSTFIELDS, $xml);
curl_exec($rq);
curl_close($rq);
}
send_pingback("… source uri …", "… target uri …");