New to our community ?

Discover a world of possibilities! Join us and explore a vibrant community where ideas flourish and connections thrive.

One of Our Valued Members

Thank you for being part of our community. Your presence enriches our shared experiences. Let's continue this journey together!

Home php codes Add Google reCAPTCHA On Registration form

Add Google reCAPTCHA On Registration form


In this post we will see how to add google reCaptcha in signup form.

Google has released the new reCAPTCHA. Using reCAPTCHA users can prove they are human without solving a CAPTCHA. They need just a single click to confirm they are not a robot. So, reCAPTCHA will protect your website from spam with better user experience. You can easily integrate Google reCAPTCHA in PHP script.
Now We have create a signup/ registration form with the new Google reCAPTCHA using PHP.The reCAPTCHA integration process is given below.

First of all we need reCAPTCHA API keys:
For adding reCAPTCHA to your website, you need to register your site and get reCAPTCHA API keys.
Register your site

Also Read :
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

Register your site at Google just click on the below link –

after click on above link here you got 2 keys.
first is site key which is used for showing captecha on client site
and another is secret key which is used to check the captecha on server end.


in this page we make our database connection.


$con= mysqli_connect("localhost","root","password","db_name")


In the index.php we make a signup form.

<!DOCTYPE html>
<title>Google Captcha Integration </title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="">

<!-- jQuery library -->
<script src=""></script>

<!-- Latest compiled JavaScript -->
<script src=""></script>

<form class="form-horizontal" method="post" action="signup.php">
                     <!-- Text input-->
<div class="form-group">
  <div class="col-md-6">
   <label class="col-md-4 control-label" for="textinput">Name</label>  
    <input id="textinput" name="name" type="text" placeholder="Enter your Name Here" class="form-control input-md">
       <div class="col-md-6">
      <label class="col-md-4 control-label" for="textinput">Email</label>
  <input id="textinput" name="email" type="text" placeholder="email" class="form-control input-md">
        <div class="col-md-6">
       <label class="col-md-4 control-label" for="textinput">Country</label>
      <input id="textinput" name="country" type="text" placeholder="Enter your country here..!!" class="form-control input-md">

    <div class="col-md-6">
   <label class="col-md-4 control-label" for="textinput">Mobile</label>  
    <input id="textinput" name="mobile" type="text" placeholder="+9123465686522" class="form-control input-md">

  <div class="col-md-12" style="margin-top: 20px;">


 <div class="g-recaptcha" data-sitekey="enter you secret key here.."></div>

<!-- Button -->
<div class="form-group">
  <label class="col-md-4 control-label" for=""></label>
  <div class="col-md-4">
	  <input  type="submit" name="sub" class="btn btn-primary  btn-lg" style="width: 250px; background-color:#1a7dc6;">

<script src="" async defer></script>


          echo '<h2>Please check the the captcha form.</h2>';
        $secretKey = " enter your secret key here..";
        $ip = $_SERVER['REMOTE_ADDR'];
        $responseKeys = json_decode($response,true);
        if(intval($responseKeys["success"]) !== 1) {
          echo '<h2>123</h2>';
        } else {
          echo '<h2>.</h2>';
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
// Check connection
if($con === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
// Escape user inputs for security

$name = mysqli_real_escape_string($con, $_REQUEST['name']);
$email = mysqli_real_escape_string($con, $_REQUEST['email']);
$country = mysqli_real_escape_string($con, $_REQUEST['country']);
$mobile = mysqli_real_escape_string($con, $_REQUEST['mobile']);
// attempt insert query execution
$sql = "INSERT INTO subscriber (name,email,country,mobile) VALUES ('$name', '$email','$country','$mobile')";
if(mysqli_query($con, $sql)){
    echo "Records added successfully.";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($con);
// close connection