2013-10-18 54 views
-3

我试图提取有关访问者的IP地址正确的信息:提取正确的信息

$ip = $_SERVER['REMOTE_ADDR']; 
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}")); // or from whatismyipaddress.com 
echo $details->city; 

,我也可以这样写:

ISP 
Organization  
City 
Region 
Country 

我可以通过json_decode和的file_get_contents提取此信息代码由我自己(geoip)

但这不是正确的方式来提取此信息(通过使用卷曲),
网站,返回正确的信息是http://whatismyipaddress.com/

我试图用geoip的,但我的PHP返回不正确的信息。

+0

可能的重复[如何通过PHP检索访问者的ISP?](http://stackoverflow.com/questions/855967/how-do-i-retrieve-the-visitors-isp-through-php) –

+0

@EmilioGort我问了更多的信息 – etnh123123

回答

1

你不能这样做,这是不可能的。你提到的这个网站(whatismyipaddress.com)有一个包含所有IP范围的大数据库,并且绑定了他们的信息。但对每个人来说都不准确 - 你只是幸运(或不)。