一小段PHP代码获取访问者IP和城市地理位置

<?php
function get_ip_place(){
$ip=file_get_contents("http://fw.qq.com/ipaddress");
$ip=str_replace('"',' ',$ip);
$ip2=explode("(",$ip);
$a=substr($ip2[1],0,-2);
$b=explode(",",$a);
return $b;
}
$ip=get_ip_place();
print_r($ip);
?>

输出结果: Array ( [0] => 202.106.149.94 [1] => [2] => 北京市 [3] => ) 说明:代码调用腾讯提供的API接口,输出数组[0]为IP地址,[2]为省份,[3]为地市

  • Tags:

发表评论

为了您的身体健康、潇洒、美丽、帅气,请不要灌水。

/ 快捷键:Ctrl+Enter