Advertisement
Guest User

jjj

a guest
Apr 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <script src='https://www.google.com/recaptcha/api.js'></script>
  2.  
  3.  
  4. <div class="g-recaptcha" data-sitekey="6LeC6VQUAAAAAPRIpR4DJ_8RhqqpvedXWGRMQl7l"></div>
  5.  
  6.  
  7. <?php
  8. function post_captcha($user_response) {
  9. $fields_string = '';
  10. $fields = array(
  11. 'secret' => '6LeC6VQUAAAAALubXKUQAo-KMamUxhlJM4Ddeud9',
  12. 'response' => $user_response
  13. );
  14. foreach($fields as $key=>$value)
  15. $fields_string .= $key . '=' . $value . '&';
  16. $fields_string = rtrim($fields_string, '&');
  17.  
  18. $ch = curl_init();
  19. curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
  20. curl_setopt($ch, CURLOPT_POST, count($fields));
  21. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  22. curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
  23.  
  24. $result = curl_exec($ch);
  25. curl_close($ch);
  26.  
  27. return json_decode($result, true);
  28. }
  29.  
  30. // Call the function post_captcha
  31. $res = post_captcha($_POST['g-recaptcha-response']);
  32.  
  33. if (!$res['success']) {
  34. // What happens when the CAPTCHA wasn't checked
  35. echo '<p>Please go back and make sure you check the security CAPTCHA box.</p><br>';
  36. } else {
  37. // If CAPTCHA is successfully completed...
  38.  
  39. // Paste mail function or whatever else you want to happen here!
  40. echo '<br><p>CAPTCHA was completed successfully!</p><br>';
  41. }
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement