gglcptch_recaptcha_http_post

Submits an HTTP POST to a reCAPTCHA server.

Description

(array) gglcptch_recaptcha_http_post( (string) $host, (string) $path, (array) $data, (int) $port = 80 ); 

Returns (array)

response

Parameters (4)

0. $host (string)
The host.
1. $path (string)
The path.
2. $data (array)
The data.
3. $port — Optional. (int) => 80
The port.

Usage

  1. if ( !function_exists( 'gglcptch_recaptcha_http_post' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-captcha-recaptcha-by-bestwebsoft/lib/recaptchalib.php'; 
  3.  
  4. // The host. 
  5. $host = ''; 
  6.  
  7. // The path. 
  8. $path = ''; 
  9.  
  10. // The data. 
  11. $data = array(); 
  12.  
  13. // The port. 
  14. $port = 80; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = gglcptch_recaptcha_http_post($host, $path, $data, $port); 
  18.  

Defined (1)

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

/lib/recaptchalib.php  
  1. function gglcptch_recaptcha_http_post($host, $path, $data, $port = 80) { 
  2.  
  3. $req = gglcptch_recaptcha_qsencode ($data); 
  4.  
  5. $http_request = "POST $path HTTP/1.0\r\n"; 
  6. $http_request .= "Host: $host\r\n"; 
  7. $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; 
  8. $http_request .= "Content-Length: " . strlen($req) . "\r\n"; 
  9. $http_request .= "User-Agent: reCAPTCHA/PHP\r\n"; 
  10. $http_request .= "\r\n"; 
  11. $http_request .= $req; 
  12.  
  13. $response = ''; 
  14. if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { 
  15. die ('Could not open socket'); 
  16.  
  17. fwrite($fs, $http_request); 
  18.  
  19. while ( !feof($fs) ) 
  20. $response .= fgets($fs, 1160); // One TCP-IP packet 
  21. fclose($fs); 
  22. $response = explode("\r\n\r\n", $response, 2); 
  23.  
  24. return $response;