This is the solution I use in classifiedsbarcelona.com to prevent Spam from India.
Usage:
Edit your commmon.php find the function isInSpamList
And replace the whole function with this code (there’s more than 1 function be aware)
////////////////////////////////////////////////////////////
function get_tag($tag,$xml){
preg_match_all('/<'.$tag.'>(.*)'.$tag.'>$/imU',$xml,$match);
return $match[1];
}
function valid_ip($ip){
return ( ! preg_match( "/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE;
}
function geoIP($stringIp=-1){
if (!valid_ip($stringIp)) $stringIp = $_SERVER['REMOTE_ADDR'];
if ($_COOKIE['geoip']){
$geoip=unserialize($_COOKIE['geoip']);
if ($geoip['ip']==$stringIp) return $geoip;//only return if IP is the same if not continue
}
$url='http://api.hostip.info/?ip='.$stringIp;// Making an API call to Hostip:
$xml = file_get_contents($url);//echo $url;
$city = get_tag('gml:name',$xml);
$city = strtolower ($city[1]);
$countryName = get_tag('countryName',$xml);
$countryName = strtolower ($countryName[0]);
$countryAbbrev = get_tag('countryAbbrev',$xml);
$countryAbbrev = strtolower ($countryAbbrev[0]);
$geoip['ip']=$stringIp;
$geoip['city']=$city;
$geoip['country']=$countryName;
$geoip['countryAb']=$countryAbbrev;
setcookie('geoip',serialize($geoip), time()+60*60*24*15);// Setting a cookie with the data, which is set to expire in half month:
return $geoip;
}
function isInSpamList($ip){//return is was taged as spam (in /manage is where we tag)
global $ocdb;
$res=$ocdb->getValue("SELECT idPost FROM ".TABLE_PREFIX."posts p where isAvailable=2 and ip='$ip' LIMIT 1","none");
if ($res==false){
$geoip=geoIP();
if ($geoip['country']=='india' || $geoip['country']=='(unknown country?)') return true;//ohohoho SPAMMER! from india
else return false;//nothing found
}
else return true;//ohohoho SPAMMER!
}
This will make everything a bit slower but works fine to me.
Thinking about to add it in newer versions….with config in the admin of course.