PHP Spam Blocker

Twitter Facebook Pinterest Google+ Stumbleupon LinkedIn


If you have a problem with Bot user’s and spam in WordPress the best solution is setting up Akismet. It’s an easy to use plug-in that just needs an API key.

For Bespoke websites there isn’t a one click plug-in but there is a super easy to use Bot database called BotScout with an API that only requires a key and CURL.

Botscout is compatible a range of off the shelf PHP systems such as PHPBB.

The following function will return

  • 0 = Not a bot
  • 1 = Is a bot
  • 2 = Failed to check for some reason
function testSpam($XIP,$XUSER,$XMAIL){  /// IP,username,email
$botdata='';
$APIKEY = 'PxX19wq5uJWiIL8'; // your optional API key
$XMAIL =urlencode($XMAIL); // make the url compliant with urlencode()
$apiquery = "http://botscout.com/test/?multi&mail=$XMAIL&ip=$XIP&key=$APIKEY"; // testing for an email address and IP

if(function_exists('file_get_contents')){
$returned_data = file_get_contents($apiquery);    // Use file_get_contents
}else{
$ch = curl_init($apiquery);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$returned_data = curl_exec($ch);
curl_close($ch);
}

if($returned_data==''){// sanity check
return 2;
}

$botdata = explode('|', $returned_data); // take the returned value and parse it (standard API, not XML)

if(substr($returned_data, 0,1) == '!'){// if the first character is an exclamation mark, an error has occurred
return 2;
}

if($botdata[3] > 0 || $botdata[5] > 0){  /// it must be spam bot
return 1;
}else{
return 0;
}

}


Posted by Adi on October 23, 2010

Twitter Facebook Pinterest Google+ Stumbleupon LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *