I have successfully implemented recaptcha on one of my sites. I have not played with him for a long time, so I donβt know exactly how Google deals with this.
But anyway, here is a simplified version of my working code, I hope this can help you.
<body> <form method="post" action=""> <div class="g-recaptcha" data-callback="processCaptcha" data-sitekey="THE_KEY_HERE"></div> <input type="submit" value="Send"/> </form> <script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=eng"></script> <script src="https://www.google.com/recaptcha/api.js" async defer></script> </body>
For a script with src = "https://www.google.com/recaptcha/api.js?hl=en", I noted a link to this link: https://developers.google.com/recaptcha/docs/language .
And server side:
<?php $secret = "THE_KEY_HERE"; $errors = []; $gRecaptchaResponse = $_POST["g-recaptcha-response"]; $recaptcha = new \ReCaptcha\ReCaptcha($secret); // this class is provided by google $resp = $recaptcha->verify($gRecaptchaResponse, $_SERVER['REMOTE_ADDR']); if (false === $resp->isSuccess()) { // $errors = $resp->getErrorCodes(); $errors[] = "Boo, you are a bot"; } if (empty($errors)) { // your success routine here } else { // your error routine here }
source share