PHP code example of ivanamat / cakephp3-captcha

1. Go to this page and download the library: Download ivanamat/cakephp3-captcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ivanamat / cakephp3-captcha example snippets


    class MyController extends AppController {

        public function initialize() {
            parent::initialize();

            $this->loadComponent('Captcha.Captcha');
        }

    }

    class MyController extends AppController {

        public $components = [
            'Captcha' => [
                'className' => 'Captcha.Captcha'
            ]
        ];

    }

    # MyController

    $ip = getenv('REMOTE_ADDR');
    $gRecaptchaResponse = $this->request->data['g-recaptcha-response'];

    $captcha = $this->Captcha->check($ip,$gRecaptchaResponse);

    if($captcha->errorCodes == null) {
        // Success
    } else {
        // Fail! Maybe a bot?
    }