对于建站的筒子们来说;垃圾广告真是让人深恶痛绝;

为了清净;搞个难以识别的验证码吧;又被用户各种吐槽;

直到后来出现了极验这个滑动的验证码;这真是一个体验好安全高的方案;

Thinkphp极验滑动验证码实现步骤解析

官网:http://www.geetest.com/ (此处应该有广告费)

示例项目:https://github.com/baijunyao/thinkphp-bjyadmin

一:注册获取key

注册;创建应用;获取key;

Thinkphp极验滑动验证码实现步骤解析

二:导入sdk

/ThinkPHP/Library/Org/Xb/Geetest.class.php

三:生成验证样式

/tpl/Home/Index/index.html

<div class="box">
  <h4>
    <a target="_blank" href="http://baijunyao.com/article/79" rel="external nofollow" >thinkphp整合系列之极验滑动验证码</a>
  </h4>
  <form id="geetest" action="{:U('Home/Index/geetest_submit_check')}" method="post">
    账号:<input type="text" name="username" value="admin">
    密码:<input type="text" name="password" value="123456">
    <input type="button" value="异步验证登录" onclick="check_verify()">
    <input type="submit" value="post提交登录">
    <div id="captcha"></div>
  </form>
</div>
<script src="/UploadFiles/2021-04-02/jquery-1.10.2.min.js">

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));
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!