|
发表于 2011-12-15 08:26:39
|
显示全部楼层
本帖最后由 longjianghu 于 2011-12-15 08:27 编辑
我用的是新浪的,但原理一样:PHP复制代码
public function getFromSina ($ipaddress)
{
$temp = '';
$data = array('country'=>'', 'province'=>'', 'city'=>'', 'district'=>'', 'isp'=>'');
$url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='.$ipaddress;
if(!empty($ipaddress))
{
$temp = $this->c->curl($url);
if($temp != '-2')
{
$temp = rtrim(substr($temp,stripos($temp,'=')+1),';');
$temp = json_decode($temp);
if(is_object($temp) && $temp->ret != '-1')
{
$data = array(
'country' => $temp->country,
'province' => $temp->province,
'city' => $temp->city,
'district' => $temp->district,
'isp' => $temp->isp
);
}
}
unset($temp);
}
return $data;
}
复制代码
|
|