Implementing Google’s New No CAPTCHA reCAPTCHA in PHP

So your visitors don’t like to enter those difficult to read distorted text as captcha in your forms? But you have to use them in order to prevent bots and spammers. If you are looking for a more human friendly way to prevent spamming then this post is for you. Google has introduced a new reCaptcha which is friendly to humans and tough on bots. How a captcha can be easy for humans? Yes it is  No CAPTCHA reCAPTCHA , it’s just a check box which can identify if it’s a human or bot. It looks so simple but a really complex and intelligent routine runs on backend when that checkbox is checked. It verifies if visitor is a human or a bot and acts accordingly.


   Live Demo              

In this post we will see how we can easily integrate this new reCaptcha using PHP.  So lets se step step how you can implement this in your website.

First you need to register here. And Register your website (domain in which you will use the captcha).

recaptcha-register site

Once you enter the domain name you will get your site key and Secret Key.

site key recaptcha

Site key is used in HTML code which would be visible to users to display the captcha widget and Secret is responsible for making communication between your site and Google. (Always keep your secret key a secret :D)

Now let’s see our simple code for the form, we have passed site key in JS code which would be used in form on pageload.

 <title>InfoTuts reCAPTCHA Demo</title>
 <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
 <script src="//"></script>
 <script type="text/javascript">
 function verify(){
 var serializedValues = jQuery("#infoForm").serialize();
 jQuery.ajax({ type: 'POST',url:"verify.php",data: serializedValues,success:function(result){
 $('#show').html('Your Form Successfully Submitted');
 return true;
 $('#show').html('Please Enter Valid Captcha');
 return false;
 var onloadCallback = function() {
 grecaptcha.render('captcha_ele', {
 'sitekey' : 'Enter Your Site Key Here', // Site key

 <div id="wrapper">
 <form action="captcha.php" onsubmit="return verify();" id="infoForm" method="POST">
 <legend>Register Form</legend>
 <div class='formwrap'>
 <span class="small" >Enter Your Name<span>
 <input type="text" id='pname' name='pname' />
 <span class="small" >Enter Your Email<span>
 <input type="email" id='pemail' name='pemail' />
 <span class="small">Enter Your Mobile Number<span>
 <input type="text" id='pnumber' name='pnumber' />
 <div id="captcha_ele"></div>
 <input type="submit" id="submit" name="submit" value="Submit">
 <div id="show"></div>
 <script src="" async defer></script>
<p style="text-align: justify;">

Now we have another file called verify.php used to recieve the data and verify the captcha.

Code for verify.php:

echo verify($_POST['g-recaptcha-response']);


function verify($response) {
$ip = $_SERVER['REMOTE_ADDR']; //server Ip
$key="Enter Your Secret Key"; // Secret key

//Build up the url
$url = '';
$full_url = $url.'?secret='.$key.'&response='.$response.'&remoteip='.$ip;

//Get the response back decode the json
$data = json_decode(file_get_contents($full_url));
//Return true or false, based on users input
if(isset($data->success) && $data->success == true) {
return True;
return False;
<p style="text-align: justify;">

Note: Our purpose is to use the reCaptcha API so we have not used database and have also not used any validation in other input fields in the form. If you guys want we will create another post with all fields validation and database.

You can download the source code and just enter your site key and secret key and implement it in your website. Please share this post with your friends and followers.

About sanjeev

Dreamer, Blogger and Thinker. I love to help people in solving their problems. You can also join me HERE

Related posts:

3 Responses so far.

  1. Hi,
    This is very helpful blog. Can you create another blog with validation form fields and database? I am starting to add this to my forms.


Leave a Reply

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