对于建站的筒子们来说;垃圾广告真是让人深恶痛绝;
为了清净;搞个难以识别的验证码吧;又被用户各种吐槽;
直到后来出现了极验这个滑动的验证码;这真是一个体验好安全高的方案;
官网:http://www.geetest.com/ (此处应该有广告费)
示例项目:https://github.com/baijunyao/thinkphp-bjyadmin
一:注册获取key
注册;创建应用;获取key;
二:导入sdk
/ThinkPHP/Library/Org/Xb/Geetest.class.php
三:生成验证样式
/tpl/Home/Index/index.html
thinkphp整合系列之极验滑动验证码
HTML
四:验证函数
/Application/Common/Common/function.php
/** * geetest检测验证码 */ function geetest_chcek_verify($data){ $geetest_id=C('GEETEST_ID'); $geetest_key=C('GEETEST_KEY'); $geetest=new \Org\Xb\Geetest($geetest_id,$geetest_key); $user_id=$_SESSION['geetest']['user_id']; if ($_SESSION['geetest']['gtserver']==1) { $result=$geetest->success_validate($data['geetest_challenge'], $data['geetest_validate'], $data['geetest_seccode'], $user_id); if ($result) { return true; } else{ return false; } }else{ if ($geetest->fail_validate($data['geetest_challenge'],$data['geetest_validate'],$data['geetest_seccode'])) { return true; }else{ return false; } } }
PHP
多谢 香蕉你个banana 童鞋的提醒;补上验证的函数;
五:php 生成验证码 并 验证
/Application/Home/Controller/IndexController.class.php
/** * geetest生成验证码 */ public function geetest_show_verify(){ $geetest_id=C('GEETEST_ID'); $geetest_key=C('GEETEST_KEY'); $geetest=new \Org\Xb\Geetest($geetest_id,$geetest_key); $user_id = "test"; $status = $geetest->pre_process($user_id); $_SESSION['geetest']=array( 'gtserver'=>$status, 'user_id'=>$user_id ); echo $geetest->get_response_str(); } /** * geetest submit 提交验证 */ public function geetest_submit_check(){ $data=I('post.'); if (geetest_chcek_verify($data)) { echo '验证成功'; }else{ echo '验证失败'; } } /** * geetest ajax 验证 */ public function geetest_ajax_check(){ $data=I('post.'); echo intval(geetest_chcek_verify($data)); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://www.cnblogs.com/ghjbk/p/7754424.html