温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ThinkPHP判断IP地区位置

发布时间:2020-07-07 22:31:46 来源:网络 阅读:344 作者:shenliyang 栏目:web开发
1.在Action目录下添加如下代码

点击(此处)折叠或打开

  1. public function index(){
  2.         $where = 'TRUE';
  3.         $membersModel = new Model("Members");
  4.         $rows = $membersModel->where($where)->select();
  5.         
  6.         if($rows){
  7.             import('ORG.Net.IpLocation');// 导入IpLocation类
  8.             $Ip = new IpLocation('UTFWry.dat'); // 实例化类 参数表示IP地址库文件。下载dat文件到net目录下
  9.             foreach ($rows as $k=>$v){
  10.                 $area = $Ip->getlocation($v['regIP']);
  11.                 $rows[$k]['location'] = isset($area['country'])?$area['country']:'未知地址';// 获取某个IP地址所在的位置
  12.             }
  13.         }
  14.         $this->assign('rows',$rows);
  15.         $this->display();
  16.     }
2.在html页面上添加

点击(此处)折叠或打开

  1. <table class="table table-striped table-hover table-condensed">
  2.             <tr>
  3.                 <th>用户名</th>
  4.                 <th>邮箱</th>
  5.                 <th>注册时间</th>
  6.                 <th>注册IP</th>
  7.                 <th>激活状态</th>
  8.             </tr>
  9.             
  10.             <volist name="rows" id="v">
  11.                 <tr>
  12.                     <th>{$v.username}</th>
  13.                     <th>{$v.email}</th>
  14.                     <th>{:date('Y-m-d H:i:s',$v['regTime'])}</th>
  15.                     <th>{$v.location}{$v.regIP}</th>
  16.                     <th><eq name="v.status" value="0"><span style="color: red">未激活</span><else/><span style="color:blue">已激活</span></eq></th>

  17.                 </tr>
  18.             </volist>
  19.         </table>



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI