PHP IP'den konum bilgilerini alma

5 Cevap php

PHP içinde kullanıcıların IP Adresi konum bilgilerini almak mümkündür.

Herhangi bir öneriniz?

Teşekkürler

5 Cevap

$ip = '98.229.152.237';
$xml = simplexml_load_file("http://ipinfodb.com/ip_query.php?ip=$ip");
print_r($xml);

Çıktı:

SimpleXMLElement Object
(
    [Ip] => 98.229.152.237
    [Status] => OK
    [CountryCode] => US
    [CountryName] => United States
    [RegionCode] => 33
    [RegionName] => New Hampshire
    [City] => Manchester
    [ZipPostalCode] => 03103
    [Latitude] => 42.9403
    [Longitude] => -71.4435
    [Timezone] => -5
    [Gmtoffset] => -5
    [Dstoffset] => -4
)

Sen Geo IP Service bazı kine kullanmanız gerekir

One free service i found on google: geoplugin. They php snipplets to use their service: geoplugin/php

PEAR GeoIP library göz atın.

Bunun için http://ipinfo.io API kullanabilirsiniz:

function ip_details($ip) {
    $json = file_get_contents("http://ipinfo.io/{$ip}");
    $details = json_decode($json);
    return $details;
}

$details = ip_details("8.8.8.8");

echo $details->city;     // => Mountain View
echo $details->country;  // => US
echo $details->org;      // => AS15169 Google Inc.
echo $details->hostname; // => google-public-dns-a.google.com

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