<?php
function getCountryByIP($ip=null){
$ch=curl_init();
$ip=$ip?:(
isset($_SERVER['REMOTE_ADDR'])?
$_SERVER['REMOTE_ADDR']:
null
);
if(!$ip)
return null;
curl_setopt($ch, CURLOPT_URL, "http://ip-api.com/json/$ip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$response=curl_exec($ch);
curl_close($ch);
$response=json_decode($response,true);
if(!is_array($response) or !isset($response['country']))
return null;
return $response['country'];
};
echo getCountryByIP()==='Russia'?'Its Russia':'Its not Russia';