Skip to content

Instantly share code, notes, and snippets.

@amityweb
Last active June 7, 2024 10:27
Show Gist options
  • Save amityweb/7175c5797d96005dce11e12677364e4b to your computer and use it in GitHub Desktop.
Save amityweb/7175c5797d96005dce11e12677364e4b to your computer and use it in GitHub Desktop.

Revisions

  1. Laurence Cope renamed this gist Jun 16, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Laurence Cope created this gist Jun 16, 2020.
    24 changes: 24 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    // Add in to HTML where you want the box to be

    <script src='https://www.google.com/recaptcha/api.js' async defer></script>
    <div class="captcha_wrapper">
    <div class="g-recaptcha" data-sitekey="YOUR_PUBLIC_KEY"></div>
    </div>

    // Add into PHP validation to check the submitted captcha response is a success or fail

    /* Google ReCaptcha Verification */
    $url = 'https://www.google.com/recaptcha/api/siteverify';
    $privatekey = "YOUR_PRIVATE_KEY";
    $response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);
    $data = json_decode($response);

    if (isset($data->success) AND $data->success==true)
    {
    // Do Success Stuff!
    }
    else
    {
    // Do Fail Stuff!
    }