[PHP] interface adds recaptcha behavior verification

Over the wall need to create a Google account and create recaptcha verification of this domain, to obtain two Secrect
https://www.google.com/recaptcha/admin

 

Html and distal increase js code, e.g.

<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>

Backend authentication code increases, for example:

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']){
    ...
}

 

Guess you like

Origin www.cnblogs.com/taoshihan/p/12016564.html