SHARE
TWEET

Demo Captcha

a guest Jun 14th, 2016 221 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     // EDIT THIS: Insert secret and site key from Google https://www.google.com/recaptcha/admin#list
  3.     $googleRecaptchaSecret = '6L...';
  4.     $googleSiteKey         = '6J...';
  5. ?>
  6. <!DOCTYPE html>
  7. <html lang="en">
  8. <head>
  9.     <meta charset="UTF-8">
  10.     <title>Google reCaptha Demo</title>
  11.     <script src='https://www.google.com/recaptcha/api.js'></script>
  12.     <style>
  13.     <!--
  14.         body {
  15.             font-family: Helvetica;
  16.             font-size: 1.2em;
  17.         }
  18.         td {
  19.             padding: 8px;
  20.         }
  21.         h1 {
  22.             color: white;
  23.             padding: 9px;
  24.             border-radius: 8px;
  25.             background-color: #C9A;
  26.         }
  27.         form {
  28.             background-color: #EDC;
  29.             border-radius: 8px;
  30.             padding: 9px;
  31.         }
  32.         .ok { color: green; }
  33.         .ko { color: red;}
  34.     -->
  35.     </style>
  36. </head>
  37. <body>
  38. <h1>Google <em>re</em>Captha Demo</h1>
  39. <?php
  40.     // Get form parameters
  41.     $input = $_REQUEST['input1'];
  42.     $captcha = $_REQUEST['g-recaptcha-response'];
  43.     $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $googleRecaptchaSecret .
  44.             "&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
  45.     if (isset($input)) {
  46.         if ($response['success']) {
  47.             print '<h2 class="ok">reCaptha has been validated!</h2>';
  48.         } else {
  49.             print '<h2 class="ko">reCaptha has not been validated!</h2>';
  50.         }
  51.         print "<h3>Data received  (\$_REQUEST)</h3><pre>";
  52.         print_r($_REQUEST);
  53.         print "\n</pre>
  54.         <h3>Response from Google</h3><pre>\n";
  55.         print_r($response);
  56.         print "</pre>\n";
  57.     }
  58. ?>
  59.  
  60. <form action="?">
  61. <!-- Hidden Fields -->
  62.  
  63. <table>
  64.     <tr>
  65.         <td>Sample Input field:</td>
  66.         <td><input name="input1"></td>
  67.     </tr>
  68.     <tr>
  69.         <td colspan="2">
  70.         <div class="g-recaptcha" data-callback="enableBtn" data-sitekey="<?php echo $googleSiteKey; ?>"></div>
  71.         </td>
  72.     </tr>
  73.    
  74.     <tr>
  75.         <td></td>
  76.         <td><input type="submit" id="buttonSubmit"></td>
  77.     </tr>
  78.    
  79. </table>
  80. </form>
  81.  
  82. <script>
  83. // disable submit button until user clicks "I'm not a robot"
  84. document.getElementById("buttonSubmit").disabled = true;
  85. function enableBtn(){
  86.     document.getElementById("buttonSubmit").disabled = false;
  87. }
  88. </script>
  89.    
  90. </body>
  91. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top