Restirct Site Access Based on Country

The title might seems kind of unspecified, but what i mean is i want the site only can be accessed by as example “Japan” country so the user from other countries can’t enter the web. At first i also kinda confuse how to do it but after some googling i got it. This is how it goes :
– First you need to download GeoIP.dat, you can download it by clicking here.
– I use the code below to restrict it :

$handle = geoip_open(“/home/xxxx/public_html/GeoIP.dat”, GEOIP_STANDARD);
if(geoip_country_name_by_addr($handle, $_SERVER['REMOTE_ADDR']) != “Japan” && geoip_country_code_by_addr($handle, $_SERVER['REMOTE_ADDR']) != “JP”)
exit(‘cannot access’);
//show your site

As i know it can blocked users from other countries than “Japan”, you can user more accurate code with geolocation but i havent try to do some research bout it. Hope this will help you all.

***Japan is only an example country

Leave a Reply

Your email address will not be published. Required fields are marked *