How to Integrate Google reCAPTCHA into website forms to avoid spam

If you created contact us form or any other form in your website, there are higher chance the online autobots filling this forms and creating spams into your inbox, to avoid this google has developed “reCAPTCHA” which allows the visitor on the form to confirm that he is a human and not robot.

For this first thing, we will need is to get keys from google website, as

1. Visit “Google Recaptcha Admin” this will require you to login to your gmail account.

2. After login you will get a form like below, for online websites select “reCAPTCHA V2”, give identifiable Label such as your domain name without extention.

3. Enter the website domain name in “domain list, you will not need to add any sub-domains.
4. Tick for selecting “Terms” and click “Register”

On next opened page, you will get SiteKey & Secret Key.

google recaptch

The next step is to use those keys for the client and server side integration. Google Already has given a example for how to do this. Its better we will reuse those.

Download the files from Github

Or like,

sudo wget -c https://raw.githubusercontent.com/google/recaptcha/1.0.0/php/recaptchalib.php 
sudo wget -c https://raw.githubusercontent.com/google/recaptcha/1.0.0/php/example-captcha.php

Modify Add the above keys into example-captcha.php , Now by referring to this example-captcha.php file, we will need to modify our contact-us.php.

And then upload both recaptchalib.php and our updated contact-us.php to your server.

Reference –
https://codeforgeek.com/2014/12/google-recaptcha-tutorial/

Leave a Comment