PHP içinde kullanıcıların IP Adresi konum bilgilerini almak mümkündür.
Herhangi bir öneriniz?
Teşekkürler
$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
Sen maxmind database için bir göz atın, ve GeoIP PECL extension olabilir.
Benim durumumda:
pecl install geoip
" ile uzantısı yükledim/usr/share/GeoIP/GeoIPCity.dat
kopyaladı yüzden PECL uzantısı buldu ettik.Eğer herhangi bir PECL eklentisini yüklemek değil, eğer aynı zamanda, size yardımcı olacak bazı PEAR paketi (PEAR::Net_GeoIP
a>) olması gerektiğini unutmayın.
Once you have installed both of those, you can use this kind of code :
$ip = '82.229.x.y'; // replace with your IP address
var_dump(geoip_record_by_name($ip));
Ve çıktı bu tür alırsınız:
array
'continent_code' => string 'EU' (length=2)
'country_code' => string 'FR' (length=2)
'country_code3' => string 'FRA' (length=3)
'country_name' => string 'France' (length=6)
'region' => string 'B9' (length=2)
'city' => string 'Lyon' (length=4)
'postal_code' => string '' (length=0)
'latitude' => float 45.75
'longitude' => float 4.84999990463
'dma_code' => int 0
'area_code' => int 0
Hangi benim durumumda, doğrudur: Ben Lyon, FR kentinde gerçekten duyuyorum.
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