homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Block access to website by country?

5+ Year Member

Msg#: 4303049 posted 7:41 pm on Apr 23, 2011 (gmt 0)

Does anyone know of a good way to block access to a website, depending on what country the user is accessing it from? E.g. I only want to allow UK visitors access and block the rest of the world, and redirect them to a page.

I've had quite an extensive Google search and so far can only find this: [countryipblocks.net...] which lets you block whole regions via IP address, but you have to do it by individual IP addresses, which you put in your htaccess file - once done, the htaccess file was 3mb! Wayyy to big

And.. I've seen the HTML5 geo-location but it's only supported by new browsers.

Any ideas?




WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4303049 posted 10:07 pm on Apr 23, 2011 (gmt 0)

Did you mean that literally? Allow one country, deny all (or just a few) others? In that case it seems like you'd be better off switching to "Deny,Allow" followed by "Deny from all" and then just a few lines for the ones you do want to let in.


WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Msg#: 4303049 posted 10:25 pm on Apr 23, 2011 (gmt 0)

The IP address method in the .htaccess file is the most efficient.

Be aware that blocking non-UK access will also remove your site from Google's index as they access from US-allocated IPs.

What about UK citizens abroad, on holiday, ex-pats, military, etc. Do you want to block all of them too?


Msg#: 4303049 posted 4:21 pm on Apr 25, 2011 (gmt 0)

the .htaccess method is quite cumbersome and not that accurate. The most accurate and up to date database is the maxmind.com paid geoip database. They also have a free version that is only 95% accurate.

If you use this, it's better to whitelist things than blacklist them. When you blacklist then when new IPs come (e.g. in a country you want to block), they won't be blocked until you update the database.

If you are implementing such a database with PHP or some scripting language, you could also choose to allow user-agent= googlebot to access your site. That would leave a backdoor for some guys who go around surfing as google bot, but there are some tradeoffs.

Another method would be to have a page somewhere that is not linked to anywhere on your site, and also not geo-blocked, then get it indexed by google, and then google bot can crawl your site via that url.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved