/** * Calls an HTTP POST function to verify if the user's guess was correct * * @param string $privateKey * @param string $remoteip * @param string $challenge * @param string $response * @param array $extra_params An array of extra variables to post to the server * @return boolean $this->is_valid property */ public static function check($privateKey, $remoteIP, $challenge, $response, $extra_params = array()) { $privateKey = $privateKey or die(self::RECAPTCHA_ERROR_KEY); $remoteIP = $remoteIP or die(self::RECAPTCHA_ERROR_REMOTE_IP); // Discard spam submissions if (!$challenge or !$response) { return self::$is_valid; } $response = self::httpPost(self::RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", array('privatekey' => $privateKey, 'remoteip' => $remoteIP, 'challenge' => $challenge, 'response' => $response) + $extra_params); $answers = explode("\n", $response[1]); if (trim($answers[0]) == 'true') { self::$is_valid = true; } else { self::$error = $answers[1]; } return self::$is_valid; }