You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.0 KiB

7 years ago
  1. <?php
  2. class Google_recaptcha {
  3. protected $secret = "";
  4. protected $api_url = "https://www.google.com/recaptcha/api/siteverify";
  5. function __construct()
  6. {
  7. $CI=& get_instance();
  8. $this->secret = $CI->site->config('google_recaptcha_secret_key');
  9. }
  10. public function check_response( $response="")
  11. {
  12. if(empty($response)) return FALSE;
  13. $curl_opt['response'] = $response;
  14. $curl_opt['secret'] = $this->secret;
  15. $ch = curl_init();
  16. curl_setopt($ch, CURLOPT_URL, $this->api_url );
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  18. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($curl_opt));
  19. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  20. curl_setopt($ch, CURLOPT_POST , TRUE);
  21. $output=curl_exec($ch);
  22. if(curl_errno($ch)) return FALSE;
  23. curl_close($ch);
  24. $output = json_decode($output, TRUE);
  25. if( isset($output['success']) && $output['success'] == true ) return TRUE;
  26. else return FALSE;
  27. }
  28. }