src/ReCaptcha/ReCaptcha.php
public function verify($response, $remoteIp = null)
    {
        // Discard empty solution submissions
        if (empty($response)) {
            $recaptchaResponse = new Response(false, array(self::E_MISSING_INPUT_RESPONSE));
            return $recaptchaResponse;
        }

        $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION);
        $rawResponse = $this->requestMethod->submit($params);
        $initialResponse = Response::fromJson($rawResponse);
        $validationErrors = array();

        if (isset($this->hostname) && strcasecmp($this->hostname, $initialResponse->getHostname()) !== 0) {
            $validationErrors[] = self::E_HOSTNAME_MISMATCH;
        }

        if (isset($this->apkPackageName) && strcasecmp($this->apkPackageName, $initialResponse->getApkPackageName()) !== 0) {
            $validationErrors[] = self::E_APK_PACKAGE_NAME_MISMATCH;
        }

        if (isset($this->action) && strcasecmp($this->action, $initialResponse->getAction()) !== 0) {
            $validationErrors[] = self::E_ACTION_MISMATCH;
        }

        if (isset($this->threshold) && $this->threshold > $initialResponse->getScore()) {
            $validationErrors[] = self::E_SCORE_THRESHOLD_NOT_MET;
        }

        if (isset($this->timeoutSeconds)) {
            $challengeTs = strtotime($initialResponse->getChallengeTs());

            if ($challengeTs > 0 && time() - $challengeTs > $this->timeoutSeconds) {
                $validationErrors[] = self::E_CHALLENGE_TIMEOUT;
            }
        }

        if (empty($validationErrors)) {
            return $initialResponse;
        }

        return new Response(
            false,
            array_merge($initialResponse->getErrorCodes(), $validationErrors),
            $initialResponse->getHostname(),
            $initialResponse->getChallengeTs(),
            $initialResponse->getApkPackageName(),
            $initialResponse->getScore(),
            $initialResponse->getAction()
        );
    }
public function verify($response, $remoteIp = null)
    {
        // Discard empty solution submissions
        if (empty($response)) {
            $recaptchaResponse = new Response(false, array(self::E_MISSING_INPUT_RESPONSE));
            return $recaptchaResponse;
        }

        $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION);
        $rawResponse = $this->requestMethod->submit($params);
        $initialResponse = Response::fromJson($rawResponse);
        $validationErrors = array();

        if (isset($this->hostname) && strcasecmp($this->hostname, $initialResponse->getHostname()) !== 0) {
            $validationErrors[] = self::E_HOSTNAME_MISMATCH;
        }

        if (isset($this->apkPackageName) && strcasecmp($this->apkPackageName, $initialResponse->getApkPackageName()) !== 0) {
            $validationErrors[] = self::E_APK_PACKAGE_NAME_MISMATCH;
        }

        if (isset($this->action) && strcasecmp($this->action, $initialResponse->getAction()) !== 0) {
            $validationErrors[] = self::E_ACTION_MISMATCH;
        }

        if (isset($this->threshold) && $this->threshold > $initialResponse->getScore()) {
            $validationErrors[] = self::E_SCORE_THRESHOLD_NOT_MET;
        }

        if (isset($this->timeoutSeconds)) {
            $challengeTs = strtotime($initialResponse->getChallengeTs());

            if ($challengeTs > 0 && time() - $challengeTs > $this->timeoutSeconds) {
                $validationErrors[] = self::E_CHALLENGE_TIMEOUT;
            }
        }

        if (empty($validationErrors)) {
            return $initialResponse;
        }

        return new Response(
            false,
            array_merge($initialResponse->getErrorCodes(), $validationErrors),
            $initialResponse->getHostname(),
            $initialResponse->getChallengeTs(),
            $initialResponse->getApkPackageName(),
            $initialResponse->getScore(),
            $initialResponse->getAction()
        );
    }
public function verify ( $ response , $ remoteIp = null ) { // Discard empty solution submissions if ( empty ( $ response ) ) { $ recaptchaResponse = new Response ( false , array ( self :: E_MISSING_INPUT_RESPONSE ) ) ; return $ recaptchaResponse ; } $ params = new RequestParameters ( $ this -> secret , $ response , $ remoteIp , self :: VERSION ) ; $ rawResponse = $ this -> requestMethod -> submit ( $ params ) ; $ initialResponse = Response :: fromJson ( $ rawResponse ) ; $ validationErrors = array ( ) ; if ( isset ( $ this -> hostname ) && strcasecmp ( $ this -> hostname , $ initialResponse -> getHostname ( ) ) !== 0 ) { $ validationErrors [ ] = self :: E_HOSTNAME_MISMATCH ; } if ( isset ( $ this -> apkPackageName ) && strcasecmp ( $ this -> apkPackageName , $ initialResponse -> getApkPackageName ( ) ) !== 0 ) { $ validationErrors [ ] = self :: E_APK_PACKAGE_NAME_MISMATCH ; } if ( isset ( $ this -> action ) && strcasecmp ( $ this -> action , $ initialResponse -> getAction ( ) ) !== 0 ) { $ validationErrors [ ] = self :: E_ACTION_MISMATCH ; } if ( isset ( $ this -> threshold ) && $ this -> threshold > $ initialResponse -> getScore ( ) ) { $ validationErrors [ ] = self :: E_SCORE_THRESHOLD_NOT_MET ; } if ( isset ( $ this -> timeoutSeconds ) ) { $ challengeTs = strtotime ( $ initialResponse -> getChallengeTs ( ) ) ; if ( $ challengeTs > 0 && time ( ) - $ challengeTs > $ this -> timeoutSeconds ) { $ validationErrors [ ] = self :: E_CHALLENGE_TIMEOUT ; } } if ( empty ( $ validationErrors ) ) { return $ initialResponse ; } return new Response ( false , array_merge ( $ initialResponse -> getErrorCodes ( ) , $ validationErrors ) , $ initialResponse -> getHostname ( ) , $ initialResponse -> getChallengeTs ( ) , $ initialResponse -> getApkPackageName ( ) , $ initialResponse -> getScore ( ) , $ initialResponse -> getAction ( ) ) ; }
Calls the reCAPTCHA siteverify API to verify whether the user passes
CAPTCHA test and additionally runs any specified additional checks

@param string $response The user response token provided by reCAPTCHA, verifying the user on your site.
@param string $remoteIp The end user's IP address.
@return Response Response from the service.
Calls the reCAPTCHA siteverify API to verify whether the user passes CAPTCHA test and additionally runs any specified additional checks