Google Recaptcha Site Key and Secret Key Generate and Integrate

Google Recaptcha Site Key and Secret Key Generate

If you also want to put I am not robot captcha on your site, then you have to first generate the site and script for your website, for that follow the steps given below.

Step 1: Open Google and search it by entering google recaptcha

Step 2: On searching google recaptcha you will get Recaptcha Admin will appear, click on it

Step 3: Here you have to enter the domain name of your site in the label and the domain on which you want to put this captcha.

Step 4: reCAPTCHA v2 Tick ​​the “I’m not a robot” checkbox let it be

Step 5: Tick ​​on “Accept the reCAPTCHA Terms of Service” then click on submit button

 

Google Recaptcha Site Key and Secret Key Integrate

Copy and paste this script code in the head tag of the page of your website on which you want to put this captcha.

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

On the page of your website where you want to display “I’m not a robot captcha, copy the code of the following div tag on that location and paste it in the place where you want to display “I’m not a robot captcha” want to

<div class="g-recaptcha" data-sitekey="your_site_key"></div>

In data-sitekey, enter the site you generated for your website.

 

For Example

<html>
  <head>
    <title>reCAPTCHA demo: Simple page</title>
    <script src="https://www.google.com/recaptcha/api.js" async defer></script>
  </head>
  <body>
    <form action="?" method="POST">
      <div class="g-recaptcha" data-sitekey="your_site_key"></div>
      <br/>
      <input type="submit" value="Submit">
    </form>
  </body>
</html>

 

 

 

Google recaptcha secret key page performance

When you submit by verifying I’m not a robot captcha from one page to another page or in the same page, it takes the page load and goes to another page, then on going to that page how will you know that the captcha is verified? The code given below has to be used for verification of the note has come or has been done,

Paste this code in the page on which you enter the link given in the action tag in the HTML form in that page

<?php
$secretKey = "enter your secretkey";
$responseKey = $_POST['g-recaptcha-response'];
$UserIP = $_POST['REOMTE_ADDR'];
$url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$UserIP";

$response = file_get_contents($url);
$response = json_decode($response);

if (isset($_POST['submit']) && $response->success)
{

?>

When the captcha is verified, then what code do you want to show, enter that code between this above and the code given below

 

<?php
}else{
echo '<script>alert("Invalid Captcha, Please try again");
window.location.href="Your Website Link";
</script>';

}
?>

Enter this code at the bottom of the same page