src/Recaptcha/Captcha/Captcha.php
public function check($captcha_challenge = false, $captcha_response = false)
    {
        if (!$this->getPrivateKey()) {
            throw new Exception('You must set private key provided by reCaptcha');
        }
        // Skip processing of empty data
        if (!$captcha_challenge && !$captcha_response) {
            if (isset($_POST['recaptcha_challenge_field']) && isset($_POST['recaptcha_response_field'])) {
                $captcha_challenge = $_POST['recaptcha_challenge_field'];
                $captcha_response = $_POST['recaptcha_response_field'];
            }
        }

        // Instance of response object
        $response = new Response();

        // Discard SPAM submissions
        if (strlen($captcha_challenge) == 0 || strlen($captcha_response) == 0) {
            $response->setValid(false);
            $response->setError('Incorrect-captcha-sol');
            return $response;
        }

        $process = $this->process(
            array(
                'privatekey' => $this->getPrivateKey(),
                'remoteip' => $this->getRemoteIp(),
                'challenge' => $captcha_challenge,
                'response' => $captcha_response
            )
        );

        $answers = explode("\n", $process [1]);

        if (trim($answers[0]) == 'true') {
            $response->setValid(true);
        } else {
            $response->setValid(false);
            $response->setError($answers[1]);
        }

        return $response;
    }
public function check($captcha_challenge = false, $captcha_response = false)
    {
        if (!$this->getPrivateKey()) {
            throw new Exception('You must set private key provided by reCaptcha');
        }
        // Skip processing of empty data
        if (!$captcha_challenge && !$captcha_response) {
            if (isset($_POST['recaptcha_challenge_field']) && isset($_POST['recaptcha_response_field'])) {
                $captcha_challenge = $_POST['recaptcha_challenge_field'];
                $captcha_response = $_POST['recaptcha_response_field'];
            }
        }

        // Instance of response object
        $response = new Response();

        // Discard SPAM submissions
        if (strlen($captcha_challenge) == 0 || strlen($captcha_response) == 0) {
            $response->setValid(false);
            $response->setError('Incorrect-captcha-sol');
            return $response;
        }

        $process = $this->process(
            array(
                'privatekey' => $this->getPrivateKey(),
                'remoteip' => $this->getRemoteIp(),
                'challenge' => $captcha_challenge,
                'response' => $captcha_response
            )
        );

        $answers = explode("\n", $process [1]);

        if (trim($answers[0]) == 'true') {
            $response->setValid(true);
        } else {
            $response->setValid(false);
            $response->setError($answers[1]);
        }

        return $response;
    }
public function check ( $ captcha_challenge = false , $ captcha_response = false ) { if ( ! $ this -> getPrivateKey ( ) ) { throw new Exception ( 'You must set private key provided by reCaptcha' ) ; } // Skip processing of empty data if ( ! $ captcha_challenge && ! $ captcha_response ) { if ( isset ( $ _POST [ 'recaptcha_challenge_field' ] ) && isset ( $ _POST [ 'recaptcha_response_field' ] ) ) { $ captcha_challenge = $ _POST [ 'recaptcha_challenge_field' ] ; $ captcha_response = $ _POST [ 'recaptcha_response_field' ] ; } } // Instance of response object $ response = new Response ( ) ; // Discard SPAM submissions if ( strlen ( $ captcha_challenge ) == 0 || strlen ( $ captcha_response ) == 0 ) { $ response -> setValid ( false ) ; $ response -> setError ( 'Incorrect-captcha-sol' ) ; return $ response ; } $ process = $ this -> process ( array ( 'privatekey' => $ this -> getPrivateKey ( ) , 'remoteip' => $ this -> getRemoteIp ( ) , 'challenge' => $ captcha_challenge , 'response' => $ captcha_response ) ) ; $ answers = explode ( "\n" , $ process [ 1 ] ) ; if ( trim ( $ answers [ 0 ] ) == 'true' ) { $ response -> setValid ( true ) ; } else { $ response -> setValid ( false ) ; $ response -> setError ( $ answers [ 1 ] ) ; } return $ response ; }
Checks and validates user's response

@param bool|string $captcha_challenge Optional challenge string. If empty, value from $_POST will be used
@param bool|string $captcha_response Optional response string. If empty, value from $_POST will be used
@throws Exception
@return Response
Checks and validates user s response