PHP reCAPTCHA V3 class
https://www.site4study.com/lesson/86<?php
include_once 'RecaptchaModule.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$recaptcha = new RecaptchaModule();
if ($recaptcha->isChecked()) {
echo 'HELLO PEOPLE';
echo '<br>' . $_POST['name'];
} else {
echo 'HELLO ROBOT';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>site4study.com ReCaptcha V3</title>
<!-- reCaptcha V3 script start -->
<script src='https://www.google.com/recaptcha/api.js?render=<?php echo RecaptchaModule::SITE_KEY; ?>'></script>
<!-- reCaptcha V3 script end -->
</head>
<body>
<form action="/index.php" method="POST">
<input type="text" name="name"/><br/>
<!-- reCaptcha V3 block start -->
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"/><br>
<!-- reCaptcha V3 block end -->
<input type="submit" value="Submit"/>
</form>
<!-- reCaptcha V3 script start -->
<script>
grecaptcha.ready(function () {
grecaptcha.execute('<?php echo RecaptchaModule::SITE_KEY; ?>', {action: 'homepage'})
.then(function (token) {
// console.log(token);
document.getElementById('g-recaptcha-response').value = token;
});
});
</script>
<!-- reCaptcha V3 script end -->
</body>
</html>