From bab50e059f5c8816deafb97860dacec790700fde Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 16 Jul 2015 22:04:59 -0400 Subject: [PATCH] #284 Add cURL support for recaptchalib_v2 --- inc/recaptcha/recaptchalib_v2.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/inc/recaptcha/recaptchalib_v2.php b/inc/recaptcha/recaptchalib_v2.php index ae467a28..9b035ada 100755 --- a/inc/recaptcha/recaptchalib_v2.php +++ b/inc/recaptcha/recaptchalib_v2.php @@ -91,6 +91,27 @@ class ReCaptcha private function _submitHTTPGet($path, $data) { $req = $this->_encodeQS($data); + // Try using cURL first. If that fails, fallback to file_get_contents + if (function_exists('curl_init')) { + $handle = curl_init($path); + $queryString = http_build_query($data, '', '&'); + $options = array( + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $queryString, + CURLOPT_HTTPHEADER => array( + 'Content-Type: application/x-www-form-urlencoded' + ), + CURLINFO_HEADER_OUT => false, + CURLOPT_HEADER => false, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_SSL_VERIFYPEER => true + ); + curl_setopt_array($handle, $options); + $response = curl_exec($handle); + curl_close($handle); + return $response; + } + $response = file_get_contents($path . $req); return $response; }