".self::$_signupUrl.""); } $this->_secret = $secret; } /** * Calls the reCAPTCHA siteverify API to verify whether the user passes * CAPTCHA test. * * @param string $remoteIp IP address of end user. * @param string $response response string from recaptcha verification. * * @return ReCaptchaResponse */ public function verifyResponse($remoteIp, $response) { // Discard empty solution submissions if ($response == NULL || strlen($response) == 0) { $recaptchaResponse = new ReCaptchaResponse(); $recaptchaResponse->success = FALSE; $recaptchaResponse->errorCodes = 'missing-input'; return $recaptchaResponse; } $getResponse = $this->_submitHttpGet( self::$_siteVerifyUrl, [ 'secret' => $this->_secret, 'remoteip' => $remoteIp, 'v' => self::$_version, 'response' => $response ] ); $answers = json_decode($getResponse, TRUE); $recaptchaResponse = new ReCaptchaResponse(); if (trim($answers['success']) == TRUE) { $recaptchaResponse->success = TRUE; } else { $recaptchaResponse->success = FALSE; $recaptchaResponse->errorCodes = $answers['error-codes']; } return $recaptchaResponse; } /** * Submits an HTTP GET to a reCAPTCHA server. * * @param string $path url path to recaptcha server. * @param array $data array of parameters to be sent. * * @return bool|string */ private function _submitHTTPGet($path, $data) { $req = $this->_encodeQS($data); $response = file_get_contents($path.$req); return $response; } /** * Encodes the given data into a query string format. * * @param array $data array of string elements to be encoded. * * @return string - encoded request. */ private function _encodeQS($data) { $req = ""; foreach ($data as $key => $value) { $req .= $key.'='.urlencode(stripslashes($value)).'&'; } // Cut the last '&' $req = substr($req, 0, strlen($req) - 1); return $req; } }