2009-12-02 45 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免费数据库更广泛。

注意当试图获得访问者额外的地址和州详细信息等我强烈建议它以一种方式显示访问者可以纠正;免得他们感到沮丧。

问候。