MovableBlog: TrackBack Form in PHP

Nuance 2.0

December 11, 2002

The form which pings the sidebar (which actually a post with, in my example, the TrackBack ID of 1) was created with —you guessed it—PHP. Here's the form. Nothing new here if you're experienced with HTML.
<form action="post.php" method="GET"> <div align="center"> <input type="hidden" name="tb_id" value="1"> <input type="hidden" name="form" value="1"> <table><tr> <td align="right"> <p>Blog Name</p> </td> <td> <input type="text" name="blog_name" size="35" value=""> </td> </tr> <tr> <td align="right"> <p>Post Title</p> </td> <td> <input type="text" name="title" size="35" value=""> </td> </tr> <tr> <td align="right"> <p>Excerpt</p> </td> <td> <input type="text" name="excerpt" size="60" maxlength="150" value=""> </td> </tr> <tr> <td align="right"> <p>Permalink</p> </td> <td> <input type="text" name="url" size="60" value=""> </td> </tr> <tr> <td></td> <td> <input type="submit" value="submit" name="submit"> </td> </tr> </table> </div> </form>
Here's the PHP file, post.php, which the form calls:
<?php $data="form=1&tb_id=1&blog_name=$blogname&title=$title &excerpt=$excerpt&url=".urlencode($url); $http_response=""; $fp=fsockopen("www.yourhost.com", 80); fputs($fp, "POST /mt/mt-tb.cgi HTTP/1.1\r\n"); fputs($fp, "Host: www.yourhost.com\r\n"); fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-Length: " . strlen($data) . "\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, "$data"); while(!feof($fp)) { $http_response.=fgets($fp, 128); } fclose($fp); list($http_headers, $http_content)=explode("\r\n\r\n", $http_response); header("Location: http://www.yourblogURL.com/"); ?>
Replace www.yourhost.com and www.yourblogURL as necessary, and make sure the line after the first appearance of www.yourhost.com points to the right location of mt-tb.cgi. Don't ask me to translate it. I grabbed it from a PHP newsgroup. It works for me, except I still can't figure out how to get just the pings from TrackBack ID 1 on the sidebar, rather than all pings, which is currently the case. What I really should have done in the first place is have it ping a TrackBack category.

Posted by Richard at 11:12