zoukankan      html  css  js  c++  java
  • [PHP] 接口增加recaptcha行为验证

    需要先翻墙创建一个谷歌账户和创建recaptcha验证的网站域名,获取到两个secrect
    https://www.google.com/recaptcha/admin

    前端增加html和js代码,例如

    <input type="hidden" name="token" id="token" />
    <script src="https://www.recaptcha.net/recaptcha/api.js?render=客户端scerect"></script>
    <script>
    grecaptcha.ready(function() {
        grecaptcha.execute('客户端scerect', {action: 'homepage'}).then(function(token) {
           $('#token').val(token);
        });
    });
    </script>

    后端增加验证代码,例如:

    post请求https://www.recaptcha.net/recaptcha/api/siteverify,
    $tokenVerify=array();
    $tokenVerify['secret']='服务端secrect';
    $tokenVerify['response']=$params['token'];
    $tokenResponse=post("https://www.recaptcha.net/recaptcha/api/siteverify", $tokenVerify);
    if(empty($tokenArr)||!$tokenArr['success']){
        ...
    }
  • 相关阅读:
    旧键盘 (20)
    人口普查(20)
    打印沙漏(20)
    程序运行时间(15)
    反转链表 (25)
    科学计数法 (20)
    组个最小数 (20)
    python yield使用
    python如何优雅判断类型
    python中如何优雅使用import
  • 原文地址:https://www.cnblogs.com/taoshihan/p/12016564.html
Copyright © 2011-2022 走看看