Google reCAPTCHA V3 integration in PHP with Demo Example

google recaptcha v3 site key & secret key

Google has launched reCAPTCHA v3 to prevent spam bots from Form Submission without any user interaction. Google reCAPTCHA v3 returns score for each request based on interactions with your site. We can say this score a spam score. With this score we can take various action in your web apps.

Today in this tutorial, we are going to show you how you can integrate Google reCAPTCHA v3 in PHP for your website.


Register your website and get reCAPTCHA v3 Secret Key

First of all you need to register your website on Google reCAPTCHA v3. To do that click here.

Now, Login to your Google account & click on the + (Plus icon) on the right side near settings icon. Fill the given form and select the reCAPTCHA type to reCAPTCHA v3, filling the form click on the Submit button.

google recaptcha v3 register new site

After submitting the form, you will get 2 information from Google:

  • Site key
  • Secret key
google recaptcha v3 site key & secret key

Integrate Google reCAPTCHA v3 in your website

To integrate it into your website you need to put it in the client side as well as in Server side. In client HTML page you need to integrate this line before the tag.

Google reCAPTCHA v3 is invisible. You will not see any captcha form like I am not robot etc of any sort on your web page. You will notice Google reCaptcha icon will appear on the bottom right corner.

You need to capture the google reCAPTCHA response in your JavaScript code. Example snippet.

Google reCAPTCHA v3 Demo Project in PHP

We have created a sample demo project in HTML, JavaScript & PHP that will verify the user interaction with Google reCAPTCHA v3. Please see the project code below.

HTML Code

We are sharing the HTML code of a demo project to understand the Google reCAPTCHA v3 for your website front-end page.

The above code will look like this in browser.

Google recaptcha v3 demo

As we do not have any checkbox (I am not robot), etc. So we need to re send this response to our PHP file, where we will varify with google varification endpoint.

In the below PHP snippet, we will post our form and here we will varify the reCAPTCHA from Google.

Google reCAPTCHA v3 Verifying the user’s response

In the above PHP code snippet, you will get the following response in $responseKeys variable from Google.

PHP (Server side) Code

Let’s see the complete PHP code that clarify the captcha.

Run the whole project on your website with correct secret & site keys. If it works fine you will see the alert message.

Google recaptcha v3 demo

Google reCAPTCHA v3 Conclusion

Cheers!! You have successfully integrated Google reCAPTCHA v3 on your website. Now you will not get any fack, spam inquiries.

Leave a Reply