PHP code example of freddiegar / g-recaptcha
1. Go to this page and download the library: Download freddiegar/g-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/ */
freddiegar / g-recaptcha example snippets
$params = [
'secret' => 'YOUR_SECRET_FROM_RECAPTCHA',
'reCaptcha' => $_POST['g-recaptcha-response']
// Optional parameters
'userAgent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36'
'ipAddress' => '127.0.0.1',
];
try {
$captcha = new ReCaptcha2($params);
$request = $captcha->request();
if ($request->isValid()) {
// Dont is bot, ready!
} else {
$error = $captcha->getErrors();
}
} catch (Exception $exception) {
$error = $exception->getMessage();
}