Feedblitz is a simple tools to integrate our website with mailing list that ready to use. From the original Feedblitz technical document, the API version provide lots of function like :
• Most recent subscriber displays on a web site.
• Integrating, embedding and hiding FeedBlitz signup with existing forms and web sites.
• Automatically creating FeedBlitz subscription and syndication accounts.
• Enabling email syndications and subscriptions to your content programmatically.
• Integrating FeedBlitz in Web 2.0 “mashups”.
• Creating RSS and OPML services based on your FeedBlitz subscriptions or syndications.
• Providing a branded or innovative management interfaces, e.g. for mobile users, IM
clients, corporate web sites and intranets.
This article will explain how to use these basic API’s using PHP, especially to register a new member. To access the API, if you dont have an account, you can register it for free at feedblitz.com because the login authentication using username and password that you own.
Requirement :
1.PHP 5.x
2.CURL module with OpenSSL
3.SimpleXML Extension (built in on PHP 5)
Accessing the API is using the format :
https://api.feedblitz.com/f.api/resourcepath
the resourcepath can be /user (user function like get information, updating, etc), /subscription (get users, searching, etc) and many more. You can read the full API documentation from feedblitz in PDF format from this link http://www.feedblitz.com/the_feedblitz_api.pdf.
if you want to use the fopen, make sure the ssl module is installed but right now i wont explain the connection with fopen here. This article will show you how to access the https with curl (make sure you enable the curl module first in your php.ini with SSL). If the Zend Core installed in your computer then you just have to login with your browser to http://localhost/ZendCore/ , go to CONFIGURATION TAB > Extensions then switch on the curl extension. After that restart your apache web server.

When your username and password is ready, create a string format to login with HTTP AUTH using the CURL in PHP.
$id = “put_your_username_here”;
$pw = “put_your_password_here”;
$idpw = “$id:$pw”;
then try to login to feedblitz using this simple script:
/**
* Get user data
*/
$resource = “user”;
$ch = curl_init() or die(curl_error());
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Allow redirection
curl_setopt($ch, CURLOPT_URL,”https://api.feedblitz.com/f.api/”.$resource);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $idpw);
$result = curl_exec($ch);
if(!$result)
{
echo curl_error($ch);die();
}
curl_close($ch);
print_r($result);
if the login process to feedblitz API is successful, the return text from feedblitz is in XML format like this one:
<?xml version=”1.0″ encoding=”UTF-8″?>
<feedblitzapi version=”1.0″ xmlns:xlink=”http://www.w3.org/1999/xlink”>
<rsp stat=”ok”>
<success code=”0″ msg=”Authorized” />
</rsp>
<user>
<id>5774746</id>
<email>your_username_shownhere</email>
<password>your_password_shownhere</password>
<mailformat>HTML</mailformat>
<keepprivate>0</keepprivate>
<channelid>1</channelid>
<status>ok</status>
<created>2007-10-07 13:06:45 -0500</created>
<ip>221.132.247.95</ip>
<failcount>0</failcount>
<reason />
<bounces />
</user>
</feedblitzapi>
that text can be parse with the xml parser.
Next, we will try to register a new subscriber to feedblitz, the methods for this is follows :
1) GET the /captcha resource image from feedblitz using API
2) Insert these values into your form and create a field in your form to capture the user’s
response.
3) POST the response and other captcha / subscription / registration data back to the
appropriate API resource.
4) Check the return document for success, warning or failure codes.
the process above will be explained for each process, and we will start from the beginning which is to get the image verification from feedblitz
1) To get the random number and image you just have to change the ResourcePath to /captha then get the Random Number and the captcha image from the feedblitz server. Because the result from curl is in xml format so we will using the SimpleXML Extension to get the data (make sure the extension is enabled by checking your phpinfo). The authentication when get the image here using the username and password like the previous script but with additional option to get the captcha image.
Example :
<?php
$id = “put_your_username_here”;
$pw = “put_your_password_here”;
$idpw = “$id:$pw”;
$ch = curl_init() or die(curl_error());
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)”);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
curl_setopt($ch, CURLOPT_URL,”https://api.feedblitz.com/f.api/captcha”);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $idpw);
$result = curl_exec($ch) or die(curl_error());
curl_close($ch);
/**
* Parsing XML with SimpleXML
*/
$xml = new SimpleXMLElement($result);
echo “Random number from Feedblitz: “.$xml->captcha->{’random’}.”<br>”;
echo “Image for authentication: “.$xml->captcha->{’img’}.”<br>”;
echo “<img src=’”.$xml->captcha->{’img’}.”‘>”;
?>
the result above is number to put in your form and the captcha image for verification.

2)Now the form will be created before we submit the user input for the next process. This form also include the variable needed for registration like random number from feedblitz server,email to register,password, and verification number from captcha image.
echo “<img src=’”.$xml->captcha->{’img’}.”‘>
<br>
<form method=’POST’ action=”>
Enter the number above <input type=’text’ name=’number_verification’><br>
Email to register <input type=’text’ name=’email’><br>
Password for the user above <input type=’text’ name=’password’>
<input type=’hidden’ name=’random_number’ value=’$random_number’>
<input type=’submit’ value=’register email to feedblitz’>
</form>”;

3) This is the most important process when we get the input from the user, prepare the xmlfile and post it to feedblitz API with CURL.
First, we will get the input variable which consist of VERIFICATION NUMBER and RANDOM NUMBER from feedblitz, EMAIL to register, and PASSWORD to login. The script below is the code snippet:
$number_verification = $_POST[’number_verification’];
$random_number = $_POST[’random_number’];
$email = $_POST[’email’];
$password = $_POST[’password’];
because the feedblitz API needs to PUT the xml file which contain the newuser to register so we have to prepare the xml from the xmltemplate then replace the data in that template then save it to file. The PUT process handled by CURL and a little tricky because the PUT option in CURL need CURLOPT_INFILE and CURLOPT_INFILESIZE which mean we have to save it to the file first then attach it to CURL before send it to feedblitz .
// prepare xml contain user to register for upload
// load from template
$string_from_template = file_get_contents(”template_newuser.xml”);
// change the data in template
$string_from_template = str_replace(”{USER_IP}”,$_SERVER[’REMOTE_ADDR’],$string_from_template);
$string_from_template = str_replace(”{RANDOM}”,$random_number,$string_from_template);
$string_from_template = str_replace(”{RESPONSE}”,$number_verification,$string_from_template);
$string_from_template = str_replace(”{EMAIL}”,$email,$string_from_template);
$string_from_template = str_replace(”{PASSWORD}”,$email,$string_from_template);
after the file is saved, call the CURL function with CURLOPT_PUT to TRUE to send the xml file.
$file_xml = getcwd().”/newuser.xml”;
echo “read xml from file: $file_xml <br>”;
$handle = fopen($file_xml, “r”);
$ch = curl_init() or die(curl_error());
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)”);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL,”https://api.feedblitz.com/f.api/user”);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $idpw);
curl_setopt($ch, CURLOPT_PUT, TRUE);
curl_setopt($ch, CURLOPT_INFILE, $handle);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file_xml));
$result = curl_exec($ch) or die(curl_error());
curl_close($ch);
4) When the curl finish the job, we can see the respons from feedblitz by echoing to the web browser. You can create your own error message based on this result.
// output the result from feedblitz
$xml = new SimpleXMLElement($result);
echo “<pre>”;print_r($xml);
if the registration form is success, the feedblitz will send the email confirmation to the email in that form.
the full complete php script example and xml template file to use in this tutorial can be downloaded here php script to access feedblitz API
More information can be read from :
http://feedblitz.blogspot.com/2006/10/feedblitz-api.html


