Advertisement
rAthus

reCAPTCHA v2

Oct 27th, 2015
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. // URL pour générer des clés: https://www.google.com/recaptcha/admin
  2.  
  3. // Affichage du bouton :
  4. // <script src='https://www.google.com/recaptcha/api.js'></script>
  5. // <div class="g-recaptcha" data-sitekey="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"></div>
  6.  
  7. // Vérification :
  8. $recaptcha_ok = -1;
  9. if (!empty($_REQUEST['g-recaptcha-response']))
  10. {
  11.     $recaptcha_ok = 0;
  12.     $url = 'https://www.google.com/recaptcha/api/siteverify';
  13.     $myvars = 'secret=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY&response='.htmlspecialchars($_POST['g-recaptcha-response'],ENT_QUOTES);
  14.     $ch = curl_init($url);
  15.     curl_setopt($ch, CURLOPT_POST, 1);
  16.     curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
  17.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  18.     curl_setopt($ch, CURLOPT_HEADER, 0);
  19.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  20.     $response = curl_exec($ch);
  21.     $json = json_decode($response);
  22.     if ($json->success)
  23.         $recaptcha_ok = 1;
  24. }
  25.  
  26. // Si le reCAPTCHA est validé, alors $recaptcha_ok = 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement