Home » PHP Hacking, Security, Server Hacking

Easily Block Visitors from a Country using HTACCESS

23 November 2009 No Comment

If you have a website, sometimes you would want to block visitors coming from a country. For example you are running a promotion for certain countries and you don’t want visitors from other country to see it. Other than that, many years ago when I was in the e-book selling business, there are two countries (I am not going to reveal) which has very high chargeback cases, meaning they buy with their credit card and then inform their credit card company that they did not authorize the charge. The credit card company will then reverse the charges, allowing the buyer to get the intangible product for free by cheating. No matter how much proof I provided to the company that charged the credit card, the buyer still gets the advantage of reversing the charges.

So my last resort was to block the whole country and sending them to a Forbidden page that says “You don’t have permission to access / on this server. Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request”. It did reduced the amount of chargebacks significantly and I didn’t notice any drops on the sales because the legitimate buyers comes from other countries.

To block a country using .htaccess, you must first need to know the IP address range but Block A Country and Country IP Blocks simplifies all that.

Block A Country is a free service that automatically generates a .htaccess with countries that you want to block. All you need to do is select the countries from the list and click the “Go” button. You will then need to create a .htaccess file at the root of your public html folder and paste the codes to that file. Do take note that the default code generated by Block A Country redirects the unwanted visitor to http://www.blockacountry.com/blocked.php

Visit Block A Country

Country IP Blocks is similar to Block A Country but it allows you to choose CIDR (Classless Inter-Domain Routing), Netmask, IP Range, .htaccess deny, .htaccess allow, Decimal/CIDR, or Hex/CIDR. It will also tell you what’s the ISO code for the country, total networks and subnets in the list.

Visit Country IP Blocks

Random Posts

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.