top of page

Blog Home // Current Post

Implementing reCAPTCHA

March 28, 2017 | Varun Mittal

It may or may not ask you a further question based on his AI report on checking the box.

In this tutorial I will be showing you how to implement Google's reCAPTCHA in your forms. reCAPTCHA is the latest version of the CAPTCHA visual cookie. It is meant to stop spammers from using spam bots to spam your forms. A very simple aid, here is how you can implement it!

 

 

 

 

 

 

How to implement?

  1. An API key is required so go to reCAPTCHA's official site while logged into your Google account. Fill in your site's domain name and your reCAPTCHA version. Click Register

  2. You shall be given a Site key and a Secret key. Keep them with you. 

  3. Type <script src='https://www.google.com/recaptcha/api.js'></script> below your form (just below the closing form tag)

  4. Place <div class="g-recaptcha" data-sitekey="xyz"></div> where you want your reCAPTCHA field to appear. NOTE: Replace 'xyz' with the Site Key Google gave you.

  5. Now we have the basic structure so let's start building the verification. Save your form as index.php

  6. Start placing PHP code at the bottom of the page. 

<?php

  foreach ($_POST as $key => $value) {

    echo '<p><strong>' . $key.':</strong> '.$value.'</p>';

  }

?>​

7.    Go to Google's Official reCAPTCHA library on GitHub and save the file in your site's root folder.

8.    Now add the following PHP code in your site. NOTE: Replace 'xyz' with your Secret Key.

<?php

// grab recaptcha library

require_once "recaptchalib.php";

// your secret key

$secret = "xyz";

// empty response

$response = null;

// check secret key

$reCaptcha = new ReCaptcha($secret);

// if submitted check response

if ($_POST["g-recaptcha-response"]) {

    $response = $reCaptcha->verifyResponse(

        $_SERVER["REMOTE_ADDR"],

        $_POST["g-recaptcha-response"]

    );

}

?>

<?php

  if ($response != null && $response->success) {

    echo "Hi " . $_POST["name"] . " (" . $_POST["email"] . "), thanks for submitting the form!";

  } else {

?>

<?php } ?>

9. Now save your file and run it. reCAPTCHA should now be working! Congratulations!

  • Facebook Social Icon
  • Twitter Social Icon
  • LinkedIn Social Icon
  • Google+ Social Icon
  • Instagram Social Icon
Featured Posts

Vector Art

Subscribe

Home

About

Careers

Company

Email Us

Forum

Feedback

Support

Terms of Service

Disclaimer

Privacy Policy

Legal

  • White Facebook Icon
  • White Twitter Icon
  • White Instagram Icon

© Orange Technologies 2017

Created by Varun

© Orange Tech.
bottom of page