homepage Welcome to WebmasterWorld Guest from 184.73.52.98
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

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?
brd1984




msg:4303051
 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?

Thanks
Ben

 

lucy24




msg:4303122
 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.

g1smd




msg:4303127
 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?

sundaridevi




msg:4303668
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved