2009-12-02 79 views

回答

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

輸出:

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 
) 
+0

感謝這就是我一直在尋找.... – Biranchi 2009-12-02 07:24:34

+0

現在不工作 – 2015-11-03 11:33:02

1
+0

你鏈接返回404 – Amirshk 2009-12-02 05:38:20

+0

對不起。下劃線被編碼。固定。 – 2009-12-02 05:44:15

3

您可以看看maxmind databaseGeoIP PECL extension

在我的情況:

  • 我已經安裝了「pecl install geoip
  • 的延伸和我已經下載了geolitecity database並將其複製到/usr/share/GeoIP/GeoIPCity.dat所以它是由PECL擴展中。

注也應該有一些PEAR包(PEAR::Net_GeoIP)來幫助你,如果你不能安裝任何PECL擴展。


一旦你已經安裝了這些,你可以使用這種代碼:

$ip = '82.229.x.y';  // replace with your IP address 
var_dump(geoip_record_by_name($ip)); 

,你會得到這樣的輸出:

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 

,在我案件的確如此:我確實在法國里昂市。

0
$ip = "66.96.147.144"; 
    $geoPlugin_array = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip)); 
    echo '<pre>'; 
    print_r($geoPlugin_array); 

OUTPUT : 
Array 
(
    [geoplugin_request] => 66.96.147.144 
    [geoplugin_status] => 200 
    [geoplugin_credit] => Some of the returned data includes GeoLite data created by MaxMind, available from http://www.maxmind.com. 
    [geoplugin_city] => Burlington 
    [geoplugin_region] => MA 
    [geoplugin_areaCode] => 781 
    [geoplugin_dmaCode] => 506 
    [geoplugin_countryCode] => US 
    [geoplugin_countryName] => United States 
    [geoplugin_continentCode] => NA 
    [geoplugin_latitude] => 42.5051 
    [geoplugin_longitude] => -71.204697 
    [geoplugin_regionCode] => MA 
    [geoplugin_regionName] => Massachusetts 
    [geoplugin_currencyCode] => USD 
    [geoplugin_currencySymbol] => $ 
    [geoplugin_currencySymbol_UTF8] => $ 
    [geoplugin_currencyConverter] => 1 
) 
1

最初的問題仍然是關係到許多;現在在2016年末)。

我經過多年的GEO定位體驗答案如下...

超越「國家」的位置信息實時報告是不可靠的。所有信息都是從IP#ISP註冊收集而來,並且主要數據供應商定期更新並傳遞相關信息。隨着IP丟失或購買,供應商必須獲得有關業務(即ISP)註冊/變更的詳細信息。大多數號碼在「塊」獲得,但不一定都在同一臺服務器相關。 *許多(如果不是大多數的話)小型私人網站向公衆提供信息時使用「Maxmind」免費數據庫並且(不正確地)將其傳遞給公衆;閱讀Maxmind警告。較小的網站沒有持續更新權限註冊的資源。

免費maxmind和「ip2location」數據庫是其付費數據庫的較小子集;請參閱他們的警告,解釋缺少的內容。

許多以塊形式購買的IP都是通過任意數量的服務器共享的,這導致信息不明確。當使用無線網絡連接到ISP時,與可能穩定的有線ADSL /有線/無線連接相反,由於ISP網絡服務器(中繼)的佈局特別廣泛,錯誤會非常令人吃驚;在大多數情況下,會話之間非靜態變化,甚至在每次會話期間甚至會變化。

作爲使用漫遊無線筆記本電腦加密狗進行ISP連接時的示例,我經常被引用爲處於另一個州,並且可能(在AU中)距離我的實際位置數百至數千公里的任何位置。

您能用...支付PHP

使用主要的數據庫供應商(即ip2location.com)可以訪問可用的服務器端腳本,這些腳本可用於獲取必要的信息。而不是從他們那裏不太可靠的免費數據庫我使用ip2location的DB1來獲取訪問者「國家」,只有我可以通過Perl和PHP做我想做的。

我也根據使用情況自動下載和解壓縮二進制數據庫,每月更新之後。很顯然,從自己的站點訪問查找可以克服遠程按需採集和處理方面的問題。

對於我的要求,ip2location FULL db比Maxmind每年要便宜得多。 *然而,Maxmind免費數據庫比ip2location免費數據庫更廣泛。

注意當試圖獲得訪問者額外的地址和州詳細信息等我強烈建議它以一種方式顯示訪問者可以糾正;免得他們感到沮喪。

問候。