【发布时间】:2012-10-26 05:04:47
【问题描述】:
可能重复:
What services can I used to find a user’s location based on their IP address?
嗨,我必须访问 ip 并将位置放在地图上,但我想要的是获取 ip 的当前位置,没有 isp 地址,有人可以建议我如何在 php 中执行此操作
【问题讨论】:
标签: php
可能重复:
What services can I used to find a user’s location based on their IP address?
嗨,我必须访问 ip 并将位置放在地图上,但我想要的是获取 ip 的当前位置,没有 isp 地址,有人可以建议我如何在 php 中执行此操作
【问题讨论】:
标签: php
$ipaddress=$_SERVER['HTTP_HOST']; $license_key="输入您的许可证密钥";
$query = "http://geoip3.maxmind.com/b?l=" . $license_key . "&i=" . $ipaddress;
$url = parse_url($query);
$host = $url["host"];
$path = $url["path"] . "?" . $url["query"];
$timeout = 1;
$fp = fsockopen ($host, 80, $errno, $errstr, $timeout)
or die('Can not open connection to server.');
if ($fp) {
fputs ($fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n");
while (!feof($fp)) {
$buf .= fgets($fp, 128);
}
$lines = explode("\n", $buf);
$data_geo = $lines[count($lines)-1];
fclose($fp);
} else {
# enter error handing code here
}
//echo $data;
$geo = explode(",",$data_geo);print_r($geo);enter code here
【讨论】:
到目前为止,您使用了什么代码?您可以使用 Maxmind API,但它限制为每天 500 个查询。
http://www.maxmind.com/en/home
您还可以使用 PHP GeoIP 扩展(如果您编译/安装它)
【讨论】:
您可以使用 3 种方法:
1) 任何地理位置数据库站点的 API。
例如:http://www.maxmind.com/en/home
2) 可下载的地理位置数据库,然后您可以参考,一旦您拥有 IP 地址即可找到位置
例如:http://www.hostip.info/dl/index.html
http://dev.maxmind.com/geoip/geoliteThis looks good
3) 从显示详细信息的站点中抓取。 - 这不是专业的,你需要稍微调整一下才不会被抓到,但它可以很好地完成工作。
【讨论】: