php 获取公网IP地址、定位所在城市
来源:互联网 发布:淘宝代理流程 编辑:程序博客网 时间:2024/04/29 12:58
本地localhost、127.0.0.1时,均能获取外网IP地址。
<?php //获取外网IP的地址,以下两个均测试成功 //$url = 'http://tool.huixiang360.com/zhanzhang/ipaddress.php'; $url = 'http://city.ip138.com/ip2city.asp'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $a = curl_exec($ch); preg_match('/\[(.*)\]/', $a, $ip); //echo $ip[1]; //根据IP地址定位所在城市 ①使用淘宝IP库 $res = @file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=$ip"); $res = json_decode($res,true); print_r($res);?>
返回结果如图:
②使用新浪IP库 $res = @file_get_contents("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=$ip"); $res = json_decode($res,true); print_r($res); ?>
返回结果如图:
阅读全文
0 0
- php 获取公网IP地址、定位所在城市
- PHP:根据IP地址获取所在城市
- PHP根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- php 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- PHP 根据IP地址获取所在城市
- 根据IP地址获取所在城市
- 根据IP地址获取所在城市
- 根据IP地址获取所在城市
- PHP根据IP地址获取所在城市具体实现
- PHP代码获取客户端IP地址经纬度及所在城市
- Android流式布局FlowLayout,一款针对Tag的布局
- 那些容易被忽视但又非常重要的安全知识
- 编译gost2.5版本
- 微服务Spring Cloud学习重点整理
- 101. Symmetric Tree
- php 获取公网IP地址、定位所在城市
- Python下的机器学习工具scikit-learn --数据预处理
- IDEA创建Web项目详细过程
- HDFS源码分析
- js弹出框、对话框、提示框、弹窗总结
- 产品经理内功修炼——产品商业化PK用户体验
- Matlab 调用.mexa64时 出现 version `GLIBCXX_3.4.20' not found 解决方法
- 对象object循环遍历的方法
- Oracle 数据文件在无备份情况下的恢复