Hey Guys original.gif

I'm writing a Trackback Class for a Piece of Software that I'm developing. However, I'm having some issues.

Firstly, although the pinging process will work for almost all blogs I have tried (Any Movable Type/Typepad Blog). It doesn't seem to work on certain Blogs (MSN Spaces for one). The Server just returns an Error 400 when trying to send the ping data.

Secondly, I'm having a problem where it just seems to randomly stop pinging sites when you have a certain amount of trackbacks to ping in one lot (i.e. Trackback URLs seperated by commas)

Here is the Script:
http://jackcomputer.no-ip.com/trackback_ping.php

I have attached the PHP class plus the code in trackback_ping.php (Excuse the messy-ness in this file, I just quickly rushed it).

Thanks in Advance biggrin.gif

trackback_ping.php:
CODE
<html>
<head>
<title>Trackback Pinger</title>
</head>
<body>
<form method="post">
Trackback URL(s) to Ping: <input type="text" name="targets" size=50><br />
Pseudo Blog Name: <input type="text" name="blog_name" size=40><br />
Pseudo Post Title: <input type="text" name="title" size=40><br />
Pseudo Permalink: <input type="text" name="url" size=50><br /><br />
Pseudo Excerpt:<br /><TEXTAREA ROWS=10 COLS=60 name="excerpt"></TEXTAREA><br />
<input type="submit" value="Send Ping!">
</form>
</body>
</html>

<?php
error_reporting(0);

require('classes/trackback.php');
$trackback = new trackback;

$blog_name = $_REQUEST['blog_name'];
$title = $_REQUEST['title'];
$excerpt = $_REQUEST['excerpt'];
$url = $_REQUEST['url'];

$targets = $_REQUEST['targets'];
$tmp = explode(",", $targets);

foreach ($tmp as $t){
if ($t){
$trackback->send_ping($t, $url, $title, $blog_name, $excerpt);
}
}
?>


classes/trackback.php:
CODE
<?php
class trackback{
/*********************************************************/
/* Ping Functions */
/*********************************************************/
function send_ping($target, $url, $title, $blog_name, $excerpt){
// Show "Pinging..." Text
ob_end_flush();
echo "Pinging <strong><em>$target</em></strong>... ";
flush();

// Parse Target
$target = parse_url($target);
if ($target["query"] != ""){
$target["query"] = "?".$target["query"];
}
if (!is_numeric($target["port"])){
$target["port"] = 80;
}

// Open the socket
$sock = fsockopen($target["host"], $target["port"], $errno, $errstr, 25);

// Couldn't Connect
if (!$sock){
$this->ping_error("$errstr (Error $errno)");
} else {
// Data to Send
$data = "url=".rawurlencode($url)."&title=".rawurlencode($title).
"&blog_name=".rawurlencode($blog_name)."&excerpt=".rawurlencode($excerpt);

// Send the trackback
fputs($sock, "POST ".$target["path"].$target["query"]." HTTP/1.1\n");
fputs($sock, "Host: ".$target["host"]."\n");
fputs($sock, "Content-type: application/x-www-form-urlencoded\n");
fputs($sock, "Content-length: ". strlen($data)."\n");
fputs($sock, "Connection: close\n\n");
fputs($sock, $data);

// Gather result
$response = "";
while(!feof($sock)) {
$response .= fgets($sock, 128);
}
fclose($sock);

$no_error_found_match = strpos($response, '<error>0</error>');

if ($no_error_found_match == true){
$this->ping_ok();
} else {
preg_match( "#<message>(.+?)</message>#", $response, $errmessage_match );
if ($errmessage_match[0]){
$xml_error_returned = $errmessage_match[0];
}
$this->ping_error($xml_error_returned);
}
}
}
function ping_error($errmsg){
ob_end_flush();
if ($errmsg){
$errmsg = "Error: ".$errmsg;
} else {
$errmsg = "Unknown Error (Are you sure the Trackback URL is Valid?)";
}
echo "<font color='red'>$errmsg</font><br />\n";
flush();
}
function ping_ok(){
ob_end_flush();
echo "<font color='green'>Done!</font><br />\n";
flush();
}

}
?>