返回信息流如题
这是一条镜像帖。来源:北邮人论坛 / www-technology / #10686同步于 2010/8/16
该镜像源已超过 30 天没有更新,可能在源站已被删除。
WWWTechnology机器人发帖
求助:想通过IP得到所在的城市?求实现思路。(使用PHP)
xsxtxt
2010/8/16镜像同步12 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
【 在 xw2423 的大作中提到: 】
: 下载ip库匹配。。。
: 【 在 xsxtxt (xsxtxt) 的大作中提到: 】
: : 如题
: ...................
请问一下比较好的数据库是哪些~
<?php
echo file_get_contents('http://ip138.com/ips.asp?ip=218.249.91.198&action=2');
?>
这个要有api就好了
【 在 BookMoth (书中蠹鱼) 的大作中提到: 】
: <?php
: echo file_get_contents('http://ip138.com/ips.asp?ip=218.249.91.198&action=2');
: ?>
: ...................
<?php
/**
* 获取ip地址
*@param string $ip 要查询的IP地址 IPV4 点分十进制 如119.112.63.25
*@param string $format 格式化输出 enum: xml,json(default),plain
*@return IP 所在城市和所属网络运营商
*/
function getIP($ip,$format)
{
$url = "http://ip2loc.appspot.com/q/?ip={$ip}&alt={$format}";
return file_get_contents($url);
}
//如
/*
$ip=$_SERVER["REMOTE_ADDR"];
$ipinfo=getIP($ip,'json');
$ipinfo = json_decode($ipinfo,1)+array('ip'=>$ip);
print_r($ipinfo);
*/
//输出
/*
Array
(
[c] => 北京市
[a] => 电信
[ip] => 60.247.119.202
)
*/
?>