Tag Archives: project - Page 2

[php] New Bing SERP checker using Windows Azure Datamarket

So, I got email from Bing Developer Team informing that Bing Search API 2.0 will be gone and moving to new platform: Windows Azure Datamarket. On my previous Bing SERP checker project, I’m using Bing Search API 2.0 which means that those codes will no longer working after 1st August.

Windows Azure Datamarket provide a trial package and a free package that has limit for 5000 requests per month. More than enough for us to toying for Bing SERP checker.

Go get your Account Key (was Application ID) : https://datamarket.azure.com/

This is the revised main function php codes so it will work on new Windows Azure Datamarket web service

//this is the main function
function b_serp($keyword, $site, $market, $api_key)
	$site=str_replace(array('http://'), '', $site);
	$context = stream_context_create(array(
		'http' => array(
		    'request_fulluri' => true,
		    'header'  => "Authorization: Basic " . base64_encode($api_key . ":" . $api_key)

	while ((!$found)&&($pos<=100)) {
		//this is the end point of microsoft azure datamarket that we should call  -- only take data from web results
		//I'm using generic file_get_contents because cURL CURLOPT_USERPWD didn't work (no idea why)
		$response=file_get_contents($end_point, 0, $context);
		foreach ($json_data->d->results as $res) {

			if (substr_count(strtolower($theweb['host']), $site))
		                return $ret;

	if (!$found)
		return NULL;

How you call it:

$account_key='put your account key here';
$res=b_serp('how to upload mp3 to youtube', 'mp32u.net', 'en-US', $account_key);

Example output:

array(3) {
  string(70) "MP32U.NET - Helping independent artist getting acknowledged in the ..."
  string(21) "http://www.mp32u.net/"

Fully working demo: http://demo.ahowto.net/new_bserp/

Actually, there are a lot of other “Search Market” that supported by Bing but I only listed some of them just for example. Download this document for complete list of Bing’s supported Search Market: http://www.bing.com/webmaster/content/developers/ADM_SCHEMA_GUIDE.docx


  1. Your PHP version must be PHP 5.2 or higher (because of json_decode command)
  2. You must activate PHP OpenSSL module (php_openssl) because we are using file_get_contents and the webservice end point must be accessed via HTTPS

Update (2012-07-20) : the endpoint URL is changed

[php] Simple captcha alternative — using math question

Today, I received some task to implement some kind of captcha in some forms in hope that this captcha will reduce the garbage and automated submission. The client asked me to implement some user friendly captcha not those that hard to see. Re-Captcha and image based captcha (such as that I implemented in mp3 to Youtube‘s contact form) is not an option. Finally, the client decided to use captcha that ask visitors some simple math problem, i.e. addition and subtraction.

I remember that one of wordpress plugin had this kind of feature. I think it’s Contact Form 7. Oh, it’s actually Really Simple Captcha plugin. But there’s another huge problem. The website is not even a wordpress-based blog/site, it’s just simple site, probably created from ground-up using Dreamweaver. So, once again, installing a plugin is not an option.

After analyzing the requirements, I decided to create it myself. This is the simple captcha features that I created:

  • it use PHP session
  • the question is just a simple math addition or subtraction. No hard to see words or image
  • the number in the math problem is small (1 – 10), 4th grader would be easily solve the math problem
  • easily added to any existing PHP forms
  • works for PHP (non-CMS) based site.

The main code is saved in file named “scaptcha.php“. This is the full source codes:


	"If you're human, what is",
	"Solve this math problem",
	"To prove you're human, please solve this",
	"What's the result of",
	"Prove that you are human! Solve this"


$sentences_idx=mt_rand(0, count($sentences)-1);  //choose which sentence to show
$_SESSION['sentence']=$sentences[$sentences_idx];  //save it to session
$operands_idx=mt_rand(0, count($operands)-1);  //choose which math operand
$_SESSION['operand']=$operands[$operands_idx];  //save it to session

$num1=mt_rand(1, 10);
$num2=mt_rand(1, 10);

switch ($_SESSION['operand']) {
	case "+":

	case "-":
                //check which one is smaller
                if ($num1<$num2) {
                        //swicth value


First, it will start PHP session. $sentence array is used to store the sentences that will be seen by visitors before the math problem. You can edit it as you wish. $operands array is the math operand supported by this simple captcha script. The script then choose which sentence to be shown and the math operand randomly. Next, it will randomly choose 2 numbers between 1 and 10, operate it mathematically then store the result in PHP session.

The form that want to use this simple captcha have to include the file above (scaptcha.php).


require_once "scaptcha.php";

Then, inside a form HTML element and --usually-- exactly before form Submit button, these codes must be placed:

echo $_SESSION['sentence']." ".$_SESSION['num1']." ".$_SESSION['operand']." ".$_SESSION['num2']." ? ";
echo "";

As you can see, the script simply show the random sentence, both numbers and operand to users then create a new text- type input where user can put it's answer. The input text is named "answer", you can change this if it's already used in different form's element name.

The target file (where the POST variables from the current form is sent and processed) must use session_start()in order to "catch" the "correct answer" of the simple captcha. Then compare the value between the correct answer saved in session and the user/visitor answer. If the answer is the same, then continue processing the form, if not, then show an error messages:


if ($_POST['answer']!=$_SESSION['result']) {
	echo "Your answer is wrong! Are you human?";
} else {
	echo "Your answer is correct!";

You have to match the $_POST['answer'] with the input text form's element name generated by the script inside the previous form (only if you changed it to other names than 'answer').

Full working demo can be tested here: http://demo.ahowto.net/scaptcha/

Online multi-currency converter mash-up

I’ve created Currency Converter Mash-up site that combine major currency converter source out there.
Site address: http://cconv.vrank.org/

Online Multi Currency Converter Screenshot

The results are taken from Google Finance currency converter, Yahoo! Finance currency converter, XE.com Universal Currency Converter, Western Union Currency Converter and Paypal. Western Union Currency Converter is quite useful if you had Google Adsense account which paid via Western Union, it gave gave you rough estimate how much will you get from Adsense in your local currency. Also, it would be useful for us that have USD currency in Paypal account but the goods that we will bought is in different currency e.g. EUR and GBP. Some source might provide less currency than others, read Currency Converter FAQ for more info.