欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

[PHP] 接口增加recaptcha行为验证

程序员文章站 2022-03-21 17:25:31
需要先*创建一个谷歌账户和创建recaptcha验证的网站域名,获取到两个secrecthttps://www.google.com/recaptcha/admin 前端增加html和js代码,例如 后端增加验证代码,例如: ......

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

[PHP] 接口增加recaptcha行为验证

 

前端增加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']){
    ...
}

 

上一篇: Hbase架构剖析

下一篇: C语言复习上