PHP code example of middlewares / recaptcha

1. Go to this page and download the library: Download middlewares/recaptcha 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/ */

    

middlewares / recaptcha example snippets


$dispatcher = new Dispatcher([
    new Middlewares\Recaptcha($secretKey),

    //in your view
    function () {
        echo '<div class="g-recaptcha" data-sitekey="XXX"></div>';
        echo '<script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>';
    }
]);

$response = $dispatcher->dispatch(new ServerRequest());

$secretKey = 'Your-Secret-Key';

$recaptcha = new Middlewares\Recaptcha($secretKey);

$responseFactory = new MyOwnResponseFactory();

$recaptcha = new Middlewares\Recaptcha($secretKey, $responseFactory);

$dispatcher = new Dispatcher([
    //detect the client ip and save it in "ip" attribute
    (new Middlewares\ClientIP())->attribute('ip'),

    //use that attribute
    (new Middlewares\Recaptcha($secretKey))->ipAttribute('ip')
]);