Robert Granlund
asked on
htaccess block all countries but the US
Is there a good and programmatic way, possibly with my htaccess or a wordpress plugin to only allow US based traffic see my site, blocking all countries but the US?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I find geolocation to be correct about 3/4 of the time ... which is somewhat better than flipping a coin. With the shortage of IPv4 blocks becoming more pressing, IP blocks supposedly assigned to the US are being used by non-US companies, and vice versa. Further, when a connection comes in on Tor or over a VPN, there's no telling where the actual origin of the connection is located.
Stronger blocking is more effective but there's a cost associated with a lost sale or lost exposure to a potential customer. At some point you have to throw up your hands and say "From this point forward, we just have to tolerate it as best we can."
If you're seeing trouble emanating from non-US IP blocks, it may be of interest to mention that using iptables to stop connections from all ex-USSR and APNIC blocks (except AU and NZ) cut a number of "issues" down substantially on our server.
Stronger blocking is more effective but there's a cost associated with a lost sale or lost exposure to a potential customer. At some point you have to throw up your hands and say "From this point forward, we just have to tolerate it as best we can."
If you're seeing trouble emanating from non-US IP blocks, it may be of interest to mention that using iptables to stop connections from all ex-USSR and APNIC blocks (except AU and NZ) cut a number of "issues" down substantially on our server.
There is also this: http://php.net/manual/en/function.geoip-country-code-by-name.php
But see the user-contributed note here: http://php.net/manual/en/book.geoip.php
But see the user-contributed note here: http://php.net/manual/en/book.geoip.php
I wrote an article on this years ago. It wasn't about blocking, but it shows some of the PHP way of approaching the issue. Probably can generalize this into something for .htaccess if you would prefer that approach.
https://www.experts-exchange.com/articles/3437/IP-Address-to-Country-in-PHP.html