reCAPTCHA is an advanced security tool designed to protect websites from automated bots and malicious activities. By implementing reCAPTCHA, website owners can ensure that their online platforms remain secure while providing a user-friendly experience for legitimate users.
composer require davidvandertuijn/recaptcha
use Davidvandertuijn\Recaptcha;
Register your site
reCAPTCHA: Easy on Humans, Hard on Bots
Add script -tag
<script src="//www.google.com/recaptcha/api.js"></script>
Add div -tag within <form>
... </form>
<div class="g-recaptcha" data-sitekey="your-sitekey-here"></div>
Verify
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$recaptcha = new Recaptcha;
$recaptcha->setSecret('your-secret-key-here');
$recaptcha->setResponse($_POST['g-recaptcha-response']);
$recaptcha->setRemoteIp($_SERVER['REMOTE_ADDR']);
if (!$recaptcha->verify()) {
// false
} else {
// true
}
}