How to select a single Country to access a Website and DENY all other Countries?


Jan 19, 2013
Reaction score
How to select a single country to access a Website and DENY access from all other countries to completely block access from the rest of the world. ?
that PHP should give you the countrycode:

if (isset($_SERVER['HTTP_CLIENT_IP'])) {$real_ip_adress=$_SERVER['HTTP_CLIENT_IP'];}
else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {$real_ip_adress=$_SERVER['HTTP_X_FORWARDED_FOR'];}
else {$real_ip_adress=$_SERVER['REMOTE_ADDR'];}
if you use wordpress you can use a plugin
(Can't post URL's)

Replace GB with the country code you want to accept.
yup simple php code to deny all ip ranges from any country can do it or modify your .htaaccess if you can to allow one particular ip range.
Mine is Wordpress site. Suppose, I want to make visible one of my Sub domain (example: for USA only and when users from other Countries tries to access that sub domain will be redirected to main domain (example: - Please help how to do? Where to put code etc?
If you are using WordPress there are plug ins that allow you to block certain IP Addresses from both local, regional
and nationwide ranges.
In wordpress
You need to buy and install CXS on your direct admin
Then go to firewall configuration setting

Select cc_allow or cc_allow_port
Then enter GB as your preferred contry...
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features and essential functions on BlackHatWorld and other forums. These functions are unrelated to ads, such as internal links and images. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock