Search code examples
php.htaccessmod-rewritespam-prevention

Can I ban or restrict a country based on IP?


I get 6-10 sign ups from places like Nigeria and Ghana in Africa. I'm currently capturing IPs so is it possible to restrict a range of IPs from a specific country?

If I can retrict them does it make more sense to add this range to my .htaccess file or restrict them at the site level?


Solution

  • You can get the maxmind database:

    http://www.maxmind.com/app/mod_geoip

    and use this code:

    GeoIPEnable On
    GeoIPDBFile /path/to/GeoIP.dat
    
    # Redirect multiple countries to a single page
    RewriteEngine on
    RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(NI|GH)$
    RewriteRule ^(.*)$ - [F]