Step 1.
註冊 API key
https://www.google.com/recaptcha
Step 2.
html
<script src='https://www.google.com/recaptcha/api.js'></script> <div class="g-recaptcha" data-sitekey="your_api_public_key"></div>
Step 3.
php
$recaptcha_secret = 'your_api_private_key'; $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $_POST['g-recaptcha-response']); $response = json_decode($response, true); if ($response["success"] !== true) { echo '<script type="text/javascript">alert("google驗證有誤,請重新操作!");</script>'; exit(); }
在〈google reCAPTCHA v2 機器人驗證〉中有 1 則留言