thinkphp标签详解(thinkphp整合系列之极验滑动验证码geetest功能)
类别:编程学习 浏览量:1683
时间:2022-03-31 00:44:31 thinkphp标签详解
thinkphp整合系列之极验滑动验证码geetest功能给一个央企做官网,登录模块用的thinkphp验证码类。但是2019-6-10到12号,国家要求央企检验官网漏洞,防止黑客攻击,正直贸易战激烈升级时期,所以各事业单位很重视官网安全性,于是乎集团总部就委托了宁波一个专业检测公司用专业工具检测出,后台验证码能用打码工具暴力破解,发函要求整改。so,就有了下面的极速验证图形
官网:http://www.geetest.com/
一:注册获取key
注册;创建应用;获取key;
二:导入sdk
/thinkphp/library/org/xb/geetestlip.class.php(此处geetestlip.class.php是我重新命名的geetest类文件,原名为class.geetestlib.php)
此处牵扯到thinkphp引入第三方类,我把第三方类放到org/util/xb下面了,同时对该类文件加入命名空间如下,否则实例化类时找不到文件
三:生成验证样式
admin/view/public/cdtsh_log_smfyws.php
|
<!doctype html> <html> <head> <meta charset= "gbk" /> <title>网站管理系统后台</title> <script language= "javascript" type= "text/javascript" src= "__js__/jquery.js" ></script> <link rel= "stylesheet" href= "__css__/jquery.validator.css" > <script type= "text/javascript" src= "__js__/jquery.validator.js" ></script> <script type= "text/javascript" src= "__js__/zh_cn.js" ></script> <link href= "__css__/admin_login.css?v20130227" rel= "stylesheet" /> <script> $(document).ready( function (){ var verifyimg = $( ".verifyimg" ).attr( "src" ); $( ".reloadverify" ).click( function (){ if ( verifyimg.indexof( '?' )>0){ $( ".verifyimg" ).attr( "src" , verifyimg+ '&random=' +math.random()); } else { $( ".verifyimg" ).attr( "src" , verifyimg.replace(/?.*$/, '' )+ '?' +math.random()); } }); }); </script> </head> <body> <li class = "wrap" > <h1><a href= "javascript:;" style= "height: 116px; width: 250px;" >后台管理中心</a></h1> <form method= "post" action= "{:u('admin/public/cdtsh_log_smfyws')}" > <li class = "login" > <ul> <li> <input class = "input" id= "username" name= "username" type= "text" title= "用户名" data-rule= "required;username" placeholder= "用户名" /> <span class = "msg-box n-right" style= "position:absolute; left: 248px; top: 12px; " for = "username" ></span> </li> <li> <input class = "input" name= "password" type= "password" title= "密码" data-rule= "required;password" placeholder= "密码" /> <span class = "msg-box n-right" style= "position:absolute;left: 248px; top: 12px;" for = "password" ></span> </li> <li> <input class = "input" id= "verify" name= "verify" type= "text" style= "width:130px;" title= "密码" data-ok= " " placeholder= "验证码" data-tip= "输入验证码!" title= "验证码" data-rule= "required;text;remote[{:u('admin/public/check_verify')}]" /> <li class = "yanzhengma_box" id= "verifyshow" > <img class = "verifyimg reloadverify" style= " cursor: pointer;" align= "right" src= "{:u('public/verify')}" title= "点击刷新" > </li> <span class = "msg-box n-right" style= "position:absolute;left: 248px; top: 12px;" for = "verify" ></span> </li> </ul> <ul> <!--<input type= "button" value= "异步验证登录" onclick= "check_verify()" >--> <!--<input type= "submit" value= "post提交登录" >--> <li id= "captcha" ></li> </ul> <button type= "submit" class = "btn" id= "subbtn" >登录</button> </li> </form> </li> <script src= "http://static.geetest.com/static/tools/gt.js" ></script> <script> var handler = function (captchaobj) { // 将验证码加到id为captcha的元素里 captchaobj.appendto( "#captcha" ); }; // 获取验证码 $.get( "{:u('admin/public/verifys')}" , function (data) { // 使用initgeetest接口 // 参数1:配置参数,与创建geetest实例时接受的参数一致 // 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendto之类的事件 initgeetest({ gt: data.gt, challenge: data.challenge, product: "float" , // 产品形式 offline: !data.success, new_captcha: 'true' , width: '260px' , }, handler); }, 'json' ); </script> </body> </html> |
四:验证函数
/application/common/common/function.php
|
/** * geetest检测验证码 */ function geetest_chcek_verify( $data ){ $geetest_id = "7149e2021d7938157e" ; $geetest_key = "62b92039e1e9cf9455" ; $geetest = new orgutilgeetestlib( $geetest_id , $geetest_key ); $user_id = $_session [ 'geetest' ][ 'user_id' ]; $ip_address = $_session [ 'geetest' ][ 'ip_address' ]; $dataa = array ( "user_id" => $user_id , # 网站用户id "client_type" => "web" , #web:电脑上的浏览器;h5:手机上的浏览器,包括移动应用内完全内置的web_view;native:通过原生sdk植入app应用的方式 "ip_address" => $ip_address , # 请在此处传输用户请求验证时所携带的ip ); if ( $_session [ 'geetest' ][ 'gtserver' ]==1){ $result = $geetest ->success_validate( $data [ 'geetest_challenge' ], $data [ 'geetest_validate' ], $data [ 'geetest_seccode' ], $dataa ); //return $result; if ( $result ) { //return 11; return true; } else { //return 22; return false; } } else { if ( $geetest ->fail_validate( $data [ 'geetest_challenge' ], $data [ 'geetest_validate' ], $data [ 'geetest_seccode' ])) { //return 33; return true; } else { //return 44; return false; } } } //获取id地址 function getip() { if (! empty ( $_server [ "http_client_ip" ])) { $cip = $_server [ "http_client_ip" ]; } elseif (! empty ( $_server [ "http_x_forwarded_for" ])) { $cip = $_server [ "http_x_forwarded_for" ]; } elseif (! empty ( $_server [ "remote_addr" ])) { $cip = $_server [ "remote_addr" ]; } else { $cip = "无法获取!" ; } return $cip ; } |
五:php 生成验证码 并 验证
|
//极速验证 public function verifys(){ //require_once dirname(dirname(dirname(__file__))) . '/lib/class.geetestlib.php'; //require_once dirname(dirname(__file__)) . '/config/config.php'; // $gtsdk = new geetestlib(captcha_id, private_key); $geetest_id = "7149e2021d7938157e9" ; $geetest_key = "62b92039e1e9cf" ; $geetest = new orgutilgeetestlib( $geetest_id , $geetest_key ); //dump($geetest);die; $user_id = "test" ; $data = array ( "user_id" => $user_id , # 网站用户id "client_type" => "web" , #web:电脑上的浏览器;h5:手机上的浏览器,包括移动应用内完全内置的web_view;native:通过原生sdk植入app应用的方式 "ip_address" => getip(), # 请在此处传输用户请求验证时所携带的ip ); $status = $geetest ->pre_process( $data ,1); //dump($status); $_session [ 'geetest' ]= array ( 'gtserver' => $status , 'user_id' => $user_id , 'ip_address' =>getip(), ); echo $geetest ->get_response_str(); } public function cdtsh_log_smfyws() { if ( $_session [ 'userid' ]) { $this ->redirect( 'admin/index/index' ); } else { if (is_post) { $username = $_post [ 'username' ]; $password = $_post [ 'password' ]; //$geetest_challenge = $_post['geetest_challenge']; //$geetest_validate = $_post['geetest_validate']; //$geetest_seccode = $_post['geetest_seccode']; $data =i( 'post.' ); if ( $data [ 'geetest_challenge' ]== "" || $data [ 'geetest_validate' ]== "" || $data [ 'geetest_seccode' ]== "" ){ $this ->error( '请进行图形验证' ); } else { //dump(geetest_chcek_verify($data)); if (geetest_chcek_verify( $data )){ //echo '验证成功'; if ( $this ->loginadmin( $username , $password )) { $data = m( "user" )->where( "username='" . $username . "' and password='" .md5( $password ). "'" )->find(); if ( $data [ "status" ] != 1) { //判断是否禁用 $this ->recordloginadmin( $_post [ 'username' ], $_post [ 'password' ], 0, "账号禁用" ); //记录登录日志 $this ->error( '该帐号禁用' ); } else { $save [ "lastlogin_time" ] = time(); $save [ "lastlogin_ip" ] = get_client_ip(); $save [ "login_num" ] = $data [ "login_num" ] + 1; $status = m( "user" )->where( array ( "id" => $data [ 'id' ]))->save( $save ); $_session [ 'userid' ] = $data [ 'id' ]; $_session [ 'user' ] = $data [ 'username' ]; $_session [ 'rid' ] = $data [ 'a_id' ]; $this ->recordloginadmin( $_post [ 'username' ], $_post [ 'password' ], 1); //记录登录日志 $this ->redirect( 'admin/index/index' ); //$this->success('登录成功',u('admin/index/index')); } } else { $this ->recordloginadmin( $_post [ 'username' ], $_post [ 'password' ], 0, "账号密码错误" ); //记录登录日志 $this ->error( '登录失败' ); } } else { //echo '图形验证失败'; $this ->error( '图形验证失败' ); } } } else { $this ->display(); } } } |
到这里就结束了
总结
以上所述是小编给大家介绍的thinkphp整合系列之极验滑动验证码geetest功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对开心学习网网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!原文链接:https://www.cnblogs.com/zmdComeOn/archive/2019/06/18/11043037.html
您可能感兴趣
- antdesignpro引入依赖如何使用(在Ant Design Pro登录功能中集成图形验证码组件的方法步骤)
- 织梦平台如何更新备案号(详解织梦dedecms短信验证码功能阿里短信)
- dedecms无缩略图怎么设置(DEDECMS转移data目录后 验证码不显示解决办法)
- dedecms授权查询(解析dedeCMS验证码的实现代码)
- vue验证码(vue_drf实现短信验证码)
- dedecms验证码要怎么设置(DEDECMS 后台验证码图片不显示的多种解决方法)
- 织梦v5.7首页二维码怎么修改(织梦dedecms登录管理后台总是验证码错误的解决方案)
- python 验证码识别模块([机器视觉]使用python自动识别验证码详解)
- dedecms验证码识别(dedecms 软件下载频道防盗链php代码)
- php 模拟登录验证码demo(PHP 模拟登陆功能实例详解)
- devc报错信息找不到(dede5.7验证码错误不显示的解决方法)
- springboot vue 异地登录(vue+springboot实现登录验证码)
- python常用的切片操作(使用python PIL库实现简单验证码的去噪方法步骤)
- dedecms后台内链如何制作(dedecms自定义表单增加验证码的方法分享)
- 如何用jquery进行表单验证(jQuery实现发送验证码控制按钮禁用功能)
- dedecms安全验证(dede验证码错误 dede验证码一直提示错误的解决方法)
- 三杨 共辅四朝帝王,构建明帝国内阁行政圈(三杨共辅四朝帝王)
- 红色文化进国企(红色文化进国企)
- 车友的选择| 轮毂该如何选(车友的选择轮毂该如何选)
- 秦海璐炫耀和王新军热恋蜜事,不料对方吐槽她吃饱后肚子撅老高(秦海璐炫耀和王新军热恋蜜事)
- 秦海璐一袭旗袍惹人倾心,将高级与淡雅展现的游刃有余(秦海璐一袭旗袍惹人倾心)
- 门外之见 海蛎子味 的表演,能走多远(门外之见海蛎子味)
热门推荐
- phplaravel一般开发什么项目(laravel 去掉index.php伪静态的操作方法)
- clickhouse 底层架构(使用 Apache Superset 可视化 ClickHouse 数据的两种方法)
- linux中apache是否启动怎么查看(Linux apache取消300错误页面Multiple Choices简单步骤)
- table 细边框
- mysql水平拓展的瓶颈(MySQL令人大跌眼镜的隐式转换)
- php创建文件(php创建多级目录与级联删除文件的方法示例)
- C#栈和堆的区别
- pandas怎么写入csv文件(Pandas读写CSV文件的方法示例)
- 怎么用python实现链表(Python3实现的判断回文链表算法示例)
- str怎么把最后一个字符去掉(因str_replace导致的注入问题总结)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9