1. Go to this page and download the library: Download germania-kg/googlerecaptcha 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/ */
germania-kg / googlerecaptcha example snippets
$app = new Slim\App;
$dic = $app->getContainer();
$dic = new Slim\Container;
$dic = new Pimple\Container;
use Germania\GoogleRecaptcha\GoogleRecaptchaServiceProvider;
// See FAQ for test keys
$public_key = "lots_of_characters_here";
$secret_key = "secret_bunch_of_characters_here";
// Pass keys to ServiceProvider
$recaptcha_services = new GoogleRecaptchaServiceProvider( $public_key, $secret_key );
// ... and optionally a PSR-3 Logger
$recaptcha_services = new GoogleRecaptchaServiceProvider( $public_key, $secret_key, $logger );
// Now register; all services will transparently be added to the $dic
$dic->register( $recaptcha_services );
use Germania\GoogleRecaptcha\GoogleRecaptchaMiddleware;
// 1. Add Service provider first
// 2. Create route
$route = $app->post('/new', function() { ...} );
// 2. Add route middleware
$route->add( 'Google.Recaptcha.Middleware' );
$route = $app->post('/new', function(Request $request, Response $response) { ...
// Grab
$recaptcha_status = $request->getAttribute("GoogleRecaptcha");
// All these are boolean
if ($recaptcha_status['failed']) { ... }
if ($recaptcha_status['success']) { ... }
if ($recaptcha_status['status'] == true) { ... }
});
// 1. Add Service provider first
// 2. Grab service.
$callable_recaptcha = $dic['Google.Recaptcha.Validator.Callable'];
// TRUE or FALSE
$valid = $callable_recaptcha( $_POST['g_recaptcha_response'], $_SERVER['REMOTE_ADDR'] );