Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to integrate google reCAPTCHA in your html form?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 343
    Comment on it

    To integrate reCAPTCHA in your HTML form, you need a public & secret key.

    You can get the both keys from this URL https://www.google.com/recaptcha/admin and it will look like

    1. Public Key: 9Madr_cSZZADgLy9zeFTEraGn9ogHhxuh_6pquJUHYyt
    2. Secret Key: 9Madr_cSZZARuPr8duJUEyaYn3ogDherh-5pqu

    You need to implemented the public key at client side i.e HTML page & secret at server side i.e. PHP Script.

    Here is the code.

    HTML Form:

    <script src='https://www.google.com/recaptcha/api.js'></script><form>
    First name:
    <input type="text" name="firstname">
    
    Last name:
    <input type="text" name="lastname">
    Captcha
    <div class="g-recaptcha" data-sitekey="paste_your_recaptcha_public_key_here"></div>
    </form>
    

    Server Side Script:

    $fileContent = '';
    if (isset($_REQUEST['g-recaptcha-response']) && !empty($_REQUEST['g-recaptcha-response'])) {
        $fileContent = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=paste_your_recaptcha_secret_key_here&response=". $_REQUEST['g-recaptcha-response']);
    }
    
    $jsonArray = json_decode($fileContent, true);
    if (isset($jsonArray['success']) && $jsonArray['success']==true) {
        // process your logic here
    } else {
        echo 'Invalid verification code, please try again!';
    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: