Nov 13
Escrito por: Pablo Veintimilla
Este script permite obtener el pais del cual proviene una dirección ip, usando PHP
/**
* getCountryByIP, get country by api, use http://www.iptoc.nl.ae/ API
* @autor Pablo Veintimilla <pveintimilla@undermedia.com.ec>
* @param ip string IP address to get country. Default The IP address from which the user is viewing the current page.
* @param type int You can choose between 3 types. When set to 1 you'll get a 2 character shortcut of the country, when set to 2 you'll get the 3 character shortcut of the country, when set to 3 you'll get the full country name. Default is 1.
*/
function getCountryByIP($ip = false, $type = 3){
$country = false;
$ip = $ip ? $ip : $_SERVER['REMOTE_ADDR'];
$api = "http://nl.ae/iptocapi.php?type=$type&ip=$ip";
@$response = file_get_contents($api);
if($response != '')
$country = $response;
return $country;
}
Ejemplos de uso:
echo getCountryByIP(); //Retorna pais, del visitante
echo getCountryByIP('190.152.189.118'); //Retorna pais del ip 190.152.189.118
echo getCountryByIP(false, 1); //Retorna 2 letras del pais del visitante
Otros post
Este post ha sido visto 676 veces

Últimos comentarios