private function verifyRecaptcha()
    {
        if (!isset($this->recaptchaClientKey)) {
            return true;
        }

        $recaptcha = $this->request->input('g-recaptcha-response');
        if (!$recaptcha) {
            return false;
        }

        $request = new Request();
        $request->setUrl('https://www.google.com/recaptcha/api/siteverify');
        $request->setBody([
            'secret' => $this->recaptchaClientSecret,
            'response' => $recaptcha,
            'remoteip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null
        ]);

        $client = Client::getInstance();

        $response = $client->post($request);
        if (!$response->getBody()) {
            return false;
        }

        $responseData = json_decode($response->getBody(), true);
        return isset($responseData['success']) && $responseData['success'];
    }
private function verifyRecaptcha()
    {
        if (!isset($this->recaptchaClientKey)) {
            return true;
        }

        $recaptcha = $this->request->input('g-recaptcha-response');
        if (!$recaptcha) {
            return false;
        }

        $request = new Request();
        $request->setUrl('https://www.google.com/recaptcha/api/siteverify');
        $request->setBody([
            'secret' => $this->recaptchaClientSecret,
            'response' => $recaptcha,
            'remoteip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null
        ]);

        $client = Client::getInstance();

        $response = $client->post($request);
        if (!$response->getBody()) {
            return false;
        }

        $responseData = json_decode($response->getBody(), true);
        return isset($responseData['success']) && $responseData['success'];
    }
private function verifyRecaptcha ( ) { if ( ! isset ( $ this -> recaptchaClientKey ) ) { return true ; } $ recaptcha = $ this -> request -> input ( 'g-recaptcha-response' ) ; if ( ! $ recaptcha ) { return false ; } $ request = new Request ( ) ; $ request -> setUrl ( 'https://www.google.com/recaptcha/api/siteverify' ) ; $ request -> setBody ( [ 'secret' => $ this -> recaptchaClientSecret , 'response' => $ recaptcha , 'remoteip' => isset ( $ _SERVER [ 'REMOTE_ADDR' ] ) ? $ _SERVER [ 'REMOTE_ADDR' ] : null ] ) ; $ client = Client :: getInstance ( ) ; $ response = $ client -> post ( $ request ) ; if ( ! $ response -> getBody ( ) ) { return false ; } $ responseData = json_decode ( $ response -> getBody ( ) , true ) ; return isset ( $ responseData [ 'success' ] ) && $ responseData [ 'success' ] ; }
Verify recaptcha code
Verify recaptcha code