ThinkPHP判断IP地区位置
admin
2023-07-05 10:44:41
0次
1.在Action目录下添加如下代码
点击(此处)折叠或打开
- public function index(){
- $where = 'TRUE';
- $membersModel = new Model("Members");
- $rows = $membersModel->where($where)->select();
-
- if($rows){
- import('ORG.Net.IpLocation');// 导入IpLocation类
- $Ip = new IpLocation('UTFWry.dat'); // 实例化类 参数表示IP地址库文件。下载dat文件到net目录下
- foreach ($rows as $k=>$v){
- $area = $Ip->getlocation($v['regIP']);
- $rows[$k]['location'] = isset($area['country'])?$area['country']:'未知地址';// 获取某个IP地址所在的位置
- }
- }
- $this->assign('rows',$rows);
- $this->display();
- }
2.在html页面上添加
点击(此处)折叠或打开
- <table class="table table-striped table-hover table-condensed">
- <tr>
- <th>用户名</th>
- <th>邮箱</th>
- <th>注册时间</th>
- <th>注册IP</th>
- <th>激活状态</th>
- </tr>
-
- <volist name="rows" id="v">
- <tr>
- <th>{$v.username}</th>
- <th>{$v.email}</th>
- <th>{:date('Y-m-d H:i:s',$v['regTime'])}</th>
- <th>{$v.location}{$v.regIP}</th>
- <th><eq name="v.status" value="0"><span style="color: red">未激活</span><else/><span style="color:blue">已激活</span></eq></th>
-
- </tr>
- </volist>
- </table>
相关内容
原创 识...
还是那句话,机圈苦大屏久已…… 虽然大屏有大屏的美,但是小屏也有小屏的俏。在大屏旗舰占据主流的手机市...
为什么今年香会基调明显变了
5月29日—31日在新加坡举行的第23届香格里拉对话会(简称“香会”),见证着元首引领下大国关系继续...