src/reCAPTCHA.php
public function isValid($response)
    {
        if (is_null($this->secretKey))
            throw new \Exception('You must set your secret key');

        if (empty($response)) {

            $this->errorCodes = array('internal-empty-response');

            return false;
        }

        $params = array(
            'secret'   => $this->secretKey,
            'response' => $response,
            'remoteip' => $this->remoteIp,
        );

        $url = self::VERIFY_URL.'?'.http_build_query($params);

        if (function_exists('curl_version'))
        {
            $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_HEADER, false);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, $this->verifyTimeout);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            $response = curl_exec($curl);
        }
        else
        {
            $response = file_get_contents($url);
        }

        if (empty($response) || is_null($response) || !$response)
        {
            return false;
        }

        $json = json_decode($response, true);

        if (isset($json['error-codes']))
        {
            $this->errorCodes = $json['error-codes'];
        }

        return $json['success'];
    }
public function isValid($response)
    {
        if (is_null($this->secretKey))
            throw new \Exception('You must set your secret key');

        if (empty($response)) {

            $this->errorCodes = array('internal-empty-response');

            return false;
        }

        $params = array(
            'secret'   => $this->secretKey,
            'response' => $response,
            'remoteip' => $this->remoteIp,
        );

        $url = self::VERIFY_URL.'?'.http_build_query($params);

        if (function_exists('curl_version'))
        {
            $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_HEADER, false);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, $this->verifyTimeout);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            $response = curl_exec($curl);
        }
        else
        {
            $response = file_get_contents($url);
        }

        if (empty($response) || is_null($response) || !$response)
        {
            return false;
        }

        $json = json_decode($response, true);

        if (isset($json['error-codes']))
        {
            $this->errorCodes = $json['error-codes'];
        }

        return $json['success'];
    }
public function isValid ( $ response ) { if ( is_null ( $ this -> secretKey ) ) throw new \ Exception ( 'You must set your secret key' ) ; if ( empty ( $ response ) ) { $ this -> errorCodes = array ( 'internal-empty-response' ) ; return false ; } $ params = array ( 'secret' => $ this -> secretKey , 'response' => $ response , 'remoteip' => $ this -> remoteIp , ) ; $ url = self :: VERIFY_URL . '?' . http_build_query ( $ params ) ; if ( function_exists ( 'curl_version' ) ) { $ curl = curl_init ( $ url ) ; curl_setopt ( $ curl , CURLOPT_HEADER , false ) ; curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ curl , CURLOPT_TIMEOUT , $ this -> verifyTimeout ) ; curl_setopt ( $ curl , CURLOPT_SSL_VERIFYPEER , false ) ; $ response = curl_exec ( $ curl ) ; } else { $ response = file_get_contents ( $ url ) ; } if ( empty ( $ response ) || is_null ( $ response ) || ! $ response ) { return false ; } $ json = json_decode ( $ response , true ) ; if ( isset ( $ json [ 'error-codes' ] ) ) { $ this -> errorCodes = $ json [ 'error-codes' ] ; } return $ json [ 'success' ] ; }
Checks the code given by the captcha

@param string $response Response code after submitting form (usually $_POST['g-recaptcha-response'])
@return bool
Checks the code given by the captcha