See this link
you can find country name from ip using this function,
function getLocationInfoByIp($ip_addr)
{
$return_data = array('country'=>'', 'city'=>'');
$ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip_addr));
if($ip_data && $ip_data->geoplugin_countryName != null)
{
$return_data['country'] = $ip_data->geoplugin_countryCode;
$return_data['city'] = $ip_data->geoplugin_city;
}
return $return_data;
}
Pass IP address in this function and you will get country info...
For ip address, you can use one of following address as ip address,
$client_ip = @$_SERVER['HTTP_CLIENT_IP'];
$forward_ip = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote_ip = @$_SERVER['REMOTE_ADDR'];
Hope this will help you...