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

newnerd

Newbie
Joined
Jan 19, 2013
Messages
49
Reaction score
9
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'];}
$cip=$real_ip_adress;
$iptolocation='http://api.hostip.info/country.php?ip='.$cip;
$creatorlocation=file_get_contents($iptolocation);
 
if you use wordpress you can use a plugin
http://wordpress.org/plugins/iq-block-country/
 
phpcode.PNG
(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: abc.mywordpresssite.com) for USA only and when users from other Countries tries to access that sub domain will be redirected to main domain (example: mywordpresssite.com). - 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.
 
Back
Top