To use Google reCAPTCHA in your website, you need to obtain a reCAPTCHA API key and secret. Follow these steps to get your reCAPTCHA credentials:
1. **Sign Up for a Google Account:**
If you don’t already have one, you need a Google account to access the Google reCAPTCHA service. Go to the Google account sign-up page (https://accounts.google.com/SignUp) and create a new account or use your existing Google account.
2. **Go to Google reCAPTCHA Website:**
Once you have a Google account, go to the Google reCAPTCHA website: https://www.google.com/recaptcha. You will need to be logged in with your Google account.
3. **Register Your Website:**
On the reCAPTCHA website, click on the “Admin Console” button in the top-right corner. You will be taken to the reCAPTCHA admin console.
4. **Create a New Site:**
In the reCAPTCHA admin console, click on the “+ icon” in the top-right corner to register a new site (your website).
5. **Enter Site Information:**
Provide a label for your website (can be any descriptive name) and specify the domains where you want to use reCAPTCHA. You can use `localhost` for testing purposes during development. Also, select the reCAPTCHA type (reCAPTCHA v2 “I’m not a robot” Checkbox or reCAPTCHA v3).
6. **Accept Terms of Service:**
Make sure to agree to the reCAPTCHA Terms of Service.
7. **Get the reCAPTCHA API Key and Secret:**
After registering your website, you will see two keys: a Site Key (public key) and a Secret Key (private key). These are your reCAPTCHA API credentials.
8. **Integrate reCAPTCHA in Your Website:**
To use reCAPTCHA in your website, you need to add the Site Key to your website’s HTML code where you want to display the reCAPTCHA widget. For example, in the contact form or login page.
For reCAPTCHA v2:
<div class="g-recaptcha" data-sitekey="YOUR_RECAPTCHA_SITE_KEY"></div>
For reCAPTCHA v3:
<script src="https://www.google.com/recaptcha/api.js?render=YOUR_RECAPTCHA_SITE_KEY"></script>
Replace `YOUR_RECAPTCHA_SITE_KEY` with the actual Site Key you obtained in step 7.
9. **Verify the reCAPTCHA Response:**
On your server-side code (e.g., PHP), you need to verify the reCAPTCHA response to ensure that the form submissions are not automated. For that, you send the response to the Google reCAPTCHA server using your Secret Key and check the response validity. Implement this verification step in your server-side form processing logic.
That’s it! Now you have successfully obtained your Google reCAPTCHA API Key and Secret and integrated reCAPTCHA into your website to protect against automated bot submissions.