Bueno, y si definitivamente decides que lo mejor para ti es la función en php pues te dejo un codigo que vi en la siguiente pagina:
http://www.cristalab.com/tips/31759/...ra-web-con-php
Código PHP:
//Obtener IP:$_SERVER["HTTP_CLIENT_IP"]!=""?$ip=$_SERVER["HTTP_CLIENT_IP"]:$ip=$_SERVER["REMOTE_ADDR"];
//Función de obtención de IP (basado en la web de webhosting.info)
function getCountry($ip_address){ //By Marc Palau (http://www.nbsp.es)
$url = "http://ip-to-country.webhosting.info/node/view/36";
$inici = "src=/flag/?type=2&cc2=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST,"POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "ip_address=$ip_address");
ob_start();
curl_exec($ch);
curl_close($ch);
$cache = ob_get_contents();
ob_end_clean();
$resto = strstr($cache,$inici);
$pais = substr($resto,strlen($inici),2);
return $pais;
}//obtención de código de país:$pais = strtolower(getCountry($ip));