gglcptch_recaptcha_check_answer

Calls an HTTP POST function to verify if the user's guess was correct.

Description

(gglcptch_ReCaptchaResponse) gglcptch_recaptcha_check_answer( (string) $privkey, (string) $remoteip, (string) $challenge, (string) $response, (array) $extra_params = array() ); 

Returns (gglcptch_ReCaptchaResponse)

Parameters (5)

0. $privkey (string)
The privkey.
1. $remoteip (string)
The remoteip.
2. $challenge (string)
The challenge.
3. $response (string)
The response.
4. $extra_params — Optional. (array) => array()
An array of extra variables to post to the server

Usage

  1. if ( !function_exists( 'gglcptch_recaptcha_check_answer' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-captcha-recaptcha-by-bestwebsoft/lib/recaptchalib.php'; 
  3.  
  4. // The privkey. 
  5. $privkey = ''; 
  6.  
  7. // The remoteip. 
  8. $remoteip = ''; 
  9.  
  10. // The challenge. 
  11. $challenge = ''; 
  12.  
  13. // The response. 
  14. $response = ''; 
  15.  
  16. // an array of extra variables to post to the server 
  17. $extra_params = array(); 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = gglcptch_recaptcha_check_answer($privkey, $remoteip, $challenge, $response, $extra_params); 
  21.  

Defined (1)

The function is defined in the following location(s).

/lib/recaptchalib.php  
  1. function gglcptch_recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array()) 
  2. if ($privkey == null || $privkey == '') { 
  3. die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); 
  4.  
  5. if ($remoteip == null || $remoteip == '') { 
  6. die ("For security reasons, you must pass the remote ip to reCAPTCHA"); 
  7.  
  8.  
  9.  
  10. //discard spam submissions 
  11. if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) { 
  12. $recaptcha_response = new gglcptch_ReCaptchaResponse(); 
  13. $recaptcha_response->is_valid = false; 
  14. $recaptcha_response->error = 'incorrect-captcha-sol'; 
  15. return $recaptcha_response; 
  16.  
  17. $response = gglcptch_recaptcha_http_post ("www.google.com", "/recaptcha/api/verify",  
  18. array ( 
  19. 'privatekey' => $privkey,  
  20. 'remoteip' => $remoteip,  
  21. 'challenge' => $challenge,  
  22. 'response' => $response 
  23. ) + $extra_params 
  24. ); 
  25.  
  26. $answers = explode ("\n", $response [1]); 
  27. $recaptcha_response = new gglcptch_ReCaptchaResponse(); 
  28.  
  29. if (trim ($answers [0]) == 'true') { 
  30. $recaptcha_response->is_valid = true; 
  31. else { 
  32. $recaptcha_response->is_valid = false; 
  33. $recaptcha_response->error = $answers [1]; 
  34. return $recaptcha_response; 
  35.