What if I could show you a way to restrict users on your website by geo-location? With just a few lines of PHP code, you can restrict, or depending on the situation, show, different content to users from different countries. I am sure you get the idea.

//get the country code
$country = file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/country");

//trim any whitespace
$c = trim($country);

//if country is Italy
if( ($c == "IT") ) {
echo "ciao";

//else if country is Britain
} else if ( ($c == "GB") ) {
echo "hello";

//else restrict access
} else {
echo "access restricted";
}

Country Code List

Here’s a list of ISO 3166-1 country codes.