通过IP获取对应ip的城市信息的函数
程序员文章站
2022-05-23 17:37:29
...
通过IP获取对应ip的城市信息的函数
/**
* 通过IP获取对应城市信息(该功能基于淘宝第三方IP库接口)
* @param $ip IP地址,如果不填写,则为当前客户端IP
* @return 如果成功,则返回数组信息,否则返回false
*/
function getIpInfo($ip){
if(empty($ip)) $ip=get_client_ip(); //get_client_ip()为tp自带函数,如没有,自己百度搜索。此处就不重复复制了
$url='http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;
$result = file_get_contents($url);
$result = json_decode($result,true);
if($result['code']!==0 || !is_array($result['data'])) return false;
return $result['data'];
}
结果例子:
Array
(
[country] => 中国
[country_id] => CN
[area] => 华南
[area_id] => 800000
[region] => 广东省
[region_id] => 440000
[city] => 深圳市
[city_id] => 440300
[county] =>
[county_id] => -1
[isp] => 电信
[isp_id] => 100017
[ip] => 113.116.200.48
)
AD:真正免费,域名+虚机+企业邮箱=0元
上一篇: 如何正确实现PHP命令行读取参数
下一篇: mysql 批量更新记录
推荐阅读
-
php下通过IP获取地理位置的代码(小偷程序)
-
php获取指定(访客)IP所有信息(地址、邮政编码、国家、经纬度等)的方法
-
Python实现通过解析域名获取ip地址的方法分析
-
android 获取当前手机的 DHCP 信息ip,server 等操作实例教程
-
php通过exif_read_data函数获取图片的exif信息
-
php下获取客户端ip地址的函数
-
通过JS获取真实的外网IP和内网IP以及IPv6地址的方法
-
php通过Chianz.com获取IP地址与地区的方法
-
做了CDN获取用户真实IP的函数代码(PHP与Asp设置方式)
-
Ajax通过XML异步提交的方法实现从数据库获取省份和城市信息实现二级联动(xml方法)