How To Use Google reCAPTCHA in PHP | Best Way to Stop Bots

By | December 5, 2019

In this tutorial you will lean How to use reCaptcha in PHP. Using Captcha in our form helps us to stop spam entries. We can stop the spammers from filling our the webforms. When we create a page for getting the enquiry from customer or any details our mail box is flooded with spam mails along with our genuine mails. Sometimes some spammers start the relat process and it ends with some serous problems like our hosting provider susoends our account or our IP gets balcklisted. To overcame from this sutuation we use CAPTCHA. You can find many scrips over the internet but best and easy to use is reCAPTCHA. Lets start how we can use reCaptcha in our PHP code.

You can follow the below instruction with code or watch the Video.

First of all we will create a from with some fields. This form is having 3 fields and a button.

As you can see we have a from. Now open the browser and search for reCaptcha you can find it at first place in Google. Click over it now follow the below instructions.

  • Now click over the admin Console which is at the top right corner
  • Now click on the plus sign which is for adding a new website.
  • Here i will use localhost. Enter the name as localhost
  • There are 2 types we can use but we will use the v2 select it. As v3 is having some problems. Now choose the challenge but most of the websites use “i am not a robot” option.
  • Accept the terms and conditions and click on the submit.
  • Now you can see 2 keys. Site key and Secret Key.
  • For using the site key we will click over the client side integration link and copy the script line and div tag of recaptcha and paste it at our form.

Script Line

Div Tag

Use the above line in your form and enter the data-sitekey.

As you can see we have completed the setting up the form now we will use this recaptcha in our PHP code for checking the requests. For this use the below code please do not forget to add the secret key.

In if else condition you can use your code. Hope you like the tutorial please share it with others. If you have any advise or have anything to update the script please let me know. Please comment below

~ Thank you for reading happy coding ~

 

Leave a Reply

Your email address will not be published. Required fields are marked *