Blocking a specific country from visiting my website

AnonLeo

Regular Member
Joined
Nov 23, 2013
Messages
363
Reaction score
275
Ok, so there is a country that I don't like, I want to block everyone from there and leave a 'Nice' message for them when they visit my website.
I want that message to appear on ALL of the pages of my website.
How can I do that?

Thanks
 
Search for GEO Redirect script. It's a simple fix, a bit trickier if you don't know any coding tho.
You use any CMD?
 
Search for GEO Redirect script. It's a simple fix, a bit trickier if you don't know any coding tho.
You use any CMD?
Thanks & which CMD are you talking about?
The cmd.exe? What does that has to do with websites
 
You can do this by blocking ip ranges from your site.

Becareful with this, as it can also block other countries along with the one you want to block.

Take a look at .htaccess IP blocking, and find out the IP ranges used in the country you want to block
 
Use some third part api, as ip ranges change too much.

You can try api.wipmania.com:

Code:
<?php
$country_code = file_get_contents('http://api.wipmania.com/' . $_SERVER['REMOTE_ADDR'] . '?' . $_SERVER['SERVER_NAME']);
echo $country_code;
if($country_code=="US"){
    echo "Greetings and stuff..."
}
?>

I used that on one of my sites before, I just tried it and it's still working.
 
Thanks & which CMD are you talking about?
The cmd.exe? What does that has to do with websites

Sorry, typo. It should be CMS (Content Management System) for example wordpress or such.

A while back I used a php script shared here at bhw, can't find it now tho.
But Bokva seems to have a solution for you.
 
Last time I checked you can install a plugin to do this the easy way if you are using WP meaning you can block
specific GEO locations. My opinion is to not do this since the traffic will not hurt anything. Even junk traffic helps your Alexa ranking.

-RK
 
Back
Top