Combatting Spammers (sploggers) – Geoip PHP mod..
-
Hey guys,
Just thought I’d share my own little script that I’ve embedded in to wp-config.php. True I should ideally place this in to a plugin, but this is just a quick example which others may find useful.
I’ve noticed that pretty much all of the ‘sploggers’ originate from China. Whilst I’m sure that there are many innocent visitors over there, I felt that my own needs for Buddypress did not extend to that country, so using Maxminds GeoIp mod, you can simply ban the entire country.
http://geolite.maxmind.com/download/geoip/api/php/
Save geoip.inc and place it somewhere on your server. Then get the ip lookup table here:
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz and place it in your home/username/ directory (underneath public_html)
You can probably set up a cron job to download the lookup table each month. As its updated monthly.
All I did was place the following in wp-config.php after /* That’s all, stop editing! Happy blogging. */.
### GEOIP BAN CHINA
include('path/to/geoip.inc');
$gi = geoip_open("path/to/GeoIP.dat",GEOIP_STANDARD);
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$country = geoip_country_code_by_addr($gi, $ip);
geoip_close($gi);
if ($country == 'CN') {
die('Service Unavailable');
}
### END GEOIPSo there you go – it simply reads in the visitors ip, then compares it to the lookup table – if the ip originates from China, then simply kill the connection. As I say, its very harsh, but personally my own project doesn’t cover that area, and so far I haven’t had any problems.
What I’m going to potentially look at, is to see if I can flag users from China… so enable them to sign up and log in, but they must ‘earn’ reputation before they can start a blog. This will cut away most of the splogger issue as spammers don’t tend to hang around.
- The topic ‘Combatting Spammers (sploggers) – Geoip PHP mod..’ is closed to new replies.