套用步驟如下。
1. 申請KEY,進入此網站點選右上角進入Admin Console,依照步驟取得網站金鑰跟密鑰
2. 登入頁(HTML)
HEAD:
<script src="https://www.google.com/recaptcha/api.js?render=網站金錀"> </script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('網站金錀', {action: 'homepage'}).then(function(token) {
var recaptchaResponse = document.getElementById('recaptchaResponse');
recaptchaResponse.value = token;
});
});
</script>
FORM:
<input type="hidden" value="" name="recaptcha_response" id="recaptchaResponse">
3. 驗證頁(PHP)
if ( !$_POST ) exit;
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
$recaptcha_secret = '密鑰';
$recaptcha_response = $_POST['recaptcha_response'];
//Make and decode POST request:
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response);
$recaptcha = json_decode($recaptcha);
if($recaptcha->success==true){
if($recaptcha->score >= 0.5) {
//PASS
} else {
//BOT
}
} else {
//FAIL
}
4. 檢查~套用v3的頁面右下角會出現Google reCAPTCHA圖示,若無則表示有缺漏得檢查。
沒有留言:
張貼留言