需要先翻墻創建一個谷歌賬戶和創建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']){ ... }
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/98243.html
標籤:PHP
下一篇:PHP 實作精確統計在線人數功能
