I have a website that needs to block a particular country based on IP address. I am more than aware that IP-based blocking is not a foolproof method for blocking visitors, but it is a necessary step in the right direction.

Since I'm using PHP, what I would do is use a GeoIP database like geoplugin.net. However, I'm curious to know if there's a better way of doing this.

The website is on a shared webserver (I don't have root access) and it is running Apache on centOS. I guess my question is "can an .htaccess file be configured to block by IP using an external source to lookup IP addresses."

link|improve this question

79% accept rate
feedback

2 Answers

up vote 4 down vote accepted

http://www.blockacountry.com

Use cautiously...I'm sure there are plenty of people on here that think you are doing the wrong thing by blocking whole countries.

link|improve this answer
Hmm, not always. Sometimes you're mandated by law to deny access to countries. Like Pandora, for example. – Mark Henderson Aug 3 '10 at 21:37
P.S. With the script that they generate, you should really get rid of the ErrorDocument 403 directive, or replace it with your own, becuase it redirects you to their own website and then launches popups. – Mark Henderson Aug 3 '10 at 21:38
I wrote this with this answer in mind: serverfault.com/questions/163502/… – Jason Berg Aug 3 '10 at 21:40
Yes. This works quite well - and yes, I'm aware that blocking countries this way is not recommended, but it's a requirement and there's not much I can do about it. Good answer, by the way. – George Edison Aug 4 '10 at 22:20
feedback

There seems to be a geoip module for apache, but the server admin might have reasons against installing it.

link|improve this answer
Ya, this would only be useful in a VPS or dedicated server setup. – George Edison Oct 22 '10 at 0:13
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.