Bir ticari GeolP Bölge Edition kullanarak dışarı ile Php kullanarak bir IP adresinden ülke adını almak nasıl. Biri bana yardımcı olur lütfen?
Kod
$json = file_get_contents('http://freegeoip.appspot.com/json/66.102.13.106');
$expression = json_decode($json);
print_r($expression);
Sonuç
stdClass Object
(
[status] => 1
[ip] => 66.102.13.106
[countrycode] => US
[countryname] => United States
[regioncode] => CA
[regionname] => California
[city] => Mountain View
[zipcode] => 94043
[latitude] => 37.4192
[longitude] => -122.057
)
CountryName almak
echo $expression->countryname;
Sonuç
United States
Kullanarak free IP geolocation webservice
Bunun için http://ipinfo.io API kullanabilirsiniz:
function get_country($ip) {
return file_get_contents("http://ipinfo.io/{$ip}/country");
}
echo get_country("8.8.8.8"); // => US
Ben bu örneklerde IP 8.8.8.8 kullanılan, ancak kullanıcının IP bilgilerini istiyorsanız sadece yerine $ _SERVER ['REMOTE_ADDR'] geçmek ettik. Daha fazla bilgi http://ipinfo.io/developers mevcuttur