Visit this link and click on get recaptcha: http://www.google.com/recaptcha/intro/index.html
Add your website and register.
Copy paste in your html or php page this code in the header, before the end of the head tag.
1 | <script src='https://www.google.com/recaptcha/api.js'></script> |
In your html form, add where the captcha UI should appear: (get the key from the google recaptha page that you should have open).
2 | <div class="g-recaptcha" data-sitekey="key"></div> |
In the process form page, add:
3 4 5 6 7 8 9 10 11 12 13 | if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){ //your site secret key $secret = 'paste here the secret key'; //get verify response data $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']); $responseData = json_decode($verifyResponse); if($responseData->success) { echo 'continue with the form stuff'; } else { exit; } |