Setup of Google reCAPTCHA



What is CAPTCHA?

The term CAPTCHA (for Completely Automated Public Turing Test To Tell Computers and Humans Apart) was coined in 2000 by Luis von Ahn, Manuel Blum, Nicholas Hopper and John Langford of Carnegie Mellon University.

A CAPTCHA is protects websites against bots by generating and grading tests that humans can pass but current computer programs cannot.

Google create program and name it reCAPTCHA.

Follow this steps for setup reCAPTCHA

  • For setup first create keys for auth.

reCAPTCHA Genrate keys Click here

  • Now in page where use captcha  add script before </head> tag close.
<script src='https://www.google.com/recaptcha/api.js'></script>

  • Add this div tag when display capcha
<div class="g-recaptcha" data-sitekey="**yoursitekey**"></div>

  • add this code when you action for captcha.
(php scipt)

if( !empty($_POST['g-recaptcha-response'])){
            $secret = '**Yoursecret**';
            $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
            $resp = json_decode($verifyResponse);
            //echo '<pre>';
            //print_r($verifyResponse) ;
            //exit();
            if($resp->success)
            {
                //your code*
            }
}

Response

{
  "success": true,
  "challenge_ts": "2017-01-19T11:20:07Z",
  "hostname": "xyz.in"
}

Comments

Popular posts from this blog

How to set self page in form action?

Let's make a webservice in php