How to block china? (and any other country)

King.

New member
Dec 26, 2010
613
6
0
I did some googling and found some ip ranges to add to my htaccess deny but I still get users from china. Is there any way to completely shut the door?
 


php code to do it:

Code:
include("geoip.inc");

include("geoipcity.inc");

include("geoipregionvars.php");

 

$gi = geoip_open("GeoLiteCity.dat", GEOIP_STANDARD);

 

$rsGeoData = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);

$country = $rsGeoData->country_code;

geoip_close($gi);




     if ($country == "CN") { $redirect = "1"; }
 
iptables is the best if you don't want Chinese users to be able to do anything.

The above code from JoseArmando is better if you want to redirect the user somewhere else.
 
@josearmando thanks man, appreciate it. But can that be done through htaccess, as I want to make the block sitewide.
 
@josearmando thanks man, appreciate it. But can that be done through htaccess, as I want to make the block sitewide.

Yes. For one of my website I blocked India and China using .htaccess. You just need to add the country IP ranges of the countries to the deny list
 
Yes. For one of my website I blocked India and China using .htaccess. You just need to add the country IP ranges of the countries to the deny list
I have shit ton of ips in there already but I still get visitors. Is there a definitive list of ips that blocks most of the traffic? Also wont adding lots of ips affect load times?
 
I can understand the desire to block hackers, but blocking out chinese traffic is dumb imo. I get a lot of sales from there. India - not so much. At all really.
 
I need to block coz they keep spamming my site using different ips, im pretty sure its just bots. My site doesn't get any legit chinese traffic anyway. I'm still looking for a reliable way to just block all of china through htaccess.
 
Hi,

You can easily block countries with cloudflare.

Just a quick note that the block option we offer for typing in country (China) in your CloudFlare threat control panel only challenges those visitors with a captcha (human visitors could still pass captcha to enter the site). Full IP or IP range blocks, of course, would still work when you put these in..