php如何获取ip的地理位置呢

WBOY
Release: 2016-06-13 12:20:56
Original
1163 people have browsed it

php怎么获取ip的地理位置呢
我调用QQ的接口

<br />function getIPLoc_QQ($queryIP){ <br />    $url = 'http://ip.qq.com/cgi-bin/searchip?searchip1='.$queryIP; <br />    $ch = curl_init($url); <br />    curl_setopt($ch,CURLOPT_ENCODING ,'gb2312'); <br />    curl_setopt($ch, CURLOPT_TIMEOUT, 10); <br />    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回 <br />    $result = curl_exec($ch); <br />    $result = mb_convert_encoding($result, "utf-8", "gb2312"); // 编码转换,否则乱码 <br />    curl_close($ch); <br />    preg_match("@<span>(.*)</span></p>@iU",$result,$ipArray); <br />    $loc = $ipArray[1]; <br />    return $loc; <br />} <br />
Copy after login

输出提示我的IP只能在局域网内部使用,我是在学校的,有没有获取地址的API啊




百度一下IP就能查出地址,这是怎么做的


------解决思路----------------------
我知道百度有个api,根据ip获取城市http://api.map.baidu.com/location/ip?ak=xxx
要申请ak
------解决思路----------------------
$url = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$Ip;
#json格式的数据
不传IP,就是你当前的公网IP的数据。
你传入内网IP(如192.168***什么的),它是肯定不能识别的哈
------解决思路----------------------
只能获取到外网的IP吧

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template