Zen Cart Logo
Forums / General Questions / What is the best method to block country access?

What is the best method to block country access?

Locked

Views: 6,876

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
26 Mar 2007, 3:20 PM
#1
intelcos avatar

intelcos

Totally Zenned

Join Date:
Apr 2004
Location:
Montreal
Posts:
584
Plugin Contributions:
0

What is the best method to block country access?

I've read many things, but here is the grunt of it.

I want to block certain countries from access to a site. Either by ip when noted via logs due to certain bs, or an entire country.

using htaccess

I've started something like this, but I fear it can degrade server performance as well.

RewriteEngine on
RewriteCond %{HTTP:Accept-Language} (aa|ab|af|am|ar|as|ay|az|ba|be|bg|bh|bi|bn|bo|br|ca|co|cs|cy|dz|eo|et|eu|fa|fi|fj|fo|fy|gd|gl|gn|gu|ha|hi|hr|hu|hy|ia|ie|ik|in|is|iw|ji|jw|ka|kk|kl|km|kn|ks|ku|ky|ln|lo|lt|lv|mg|mi|mk|ml|mn|mo|mr|ms|mt|my|na|ne|oc|om|or|pa|pl|ps|qu|rm|rn|ro|ru|rw|sa|sd|sg|sh|si|sk|sl|sm|sn|so|sq|sr|ss|st|su|sw|ta|te|tg|th|ti|tk|tl|tn|to|tr|ts|tt|tw|uk|ur|uz|vi|vo|wo|xh|yo|zu) [NC]
RewriteRule .* http://www.whatever.com/noaccess.htm [R,L]

<Files *.php>
Order Deny,Allow
Deny from all
</Files>

<Files *.jsp>
Order Deny,Allow
Deny from all
</Files>

<Limit PUT DELETE> order deny,allow deny from all </Limit> <Limit GET POST> order deny,allow deny from .pl deny from .cz deny from .ru deny from .tr deny from .aa deny from .ab deny from .af deny from .am deny from .ar </Limit> <Limit GET> deny from 74.6.67.116 deny from 74.6.70.52 deny from 74.6.74.58 deny from 74.6.70.28

and so on, due to the ip list it is getting booksize like a rampant bunny...

So, somewhat lost and stuck...ideas anyone?

25 Apr 2007, 1:33 PM
#2
wondergirl avatar

wondergirl

Zen Follower

Join Date:
Jul 2005
Posts:
108
Plugin Contributions:
0

Re: What is the best method to block country access?

Intel: Is this working for you? and if so where do you put this information? I am having issues with "phoney customer memberships" from countries lately, and want to nip it in the bud.

25 Apr 2007, 2:52 PM
#3
ryanf avatar

ryanf

New Zenner

Join Date:
Mar 2007
Posts:
32
Plugin Contributions:
0

Re: What is the best method to block country access?

check out http://www.hostip.info/use.html I use it successfully to get the users state location so that on forms the state field is preselected in the drop down box.

Here is the code I use for the state but I know you can get the county pretty easily too.

<select name="state" id="newsletter_state">
<?php
$request = 'http://api.hostip.info/get_html.php?ip='.$_SERVER["REMOTE_ADDR"];
$session = curl_init($request);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session); 

$parts = explode("City:",$response);
$parts = explode(",", $parts[1]);
$city = trim($parts[0]);
$state = strtoupper(trim($parts[1]));
echo '<option value="Outside US">Outside US</option>';
foreach($states as $option => $value) {
    echo '<option value="'.$option.'"';
    if ($option == $state) {
        echo ' selected="selected"';
    }
    echo '>'.$option.'  </option>';
}
?>
</select>    
27 Apr 2009, 9:49 AM
#4
xcooling avatar

xcooling

New Zenner

Join Date:
Apr 2008
Location:
internet
Posts:
41
Plugin Contributions:
0

Re: What is the best method to block country access?

that will make your website CRAZY slow..

as it has to download a file every time and prase it.

27 Apr 2009, 9:51 AM
#5
xcooling avatar

xcooling

New Zenner

Join Date:
Apr 2008
Location:
internet
Posts:
41
Plugin Contributions:
0

Re: What is the best method to block country access?

.htaccess method is the quickest, under 1/10 sec.

im working on a php method for one of my clients that will be built into zencart, without the performance implications.