css
—
.grecaptcha-badge {
visibility: hidden;
}
html
—-
<!– <input name »recaptcha_response » id= »recaptchaResponse » /> –>
js
—
//https://www.google.com/recaptcha/api.js?render=ma_cle_secrete
grecaptcha.ready(function() {
grecaptcha.execute(‘6LeT1IkdAAAAALikWkCzPrPeP6hF1ex2UycOtS9K’, { action: ‘submit’ }).then(function(token) {
var recaptchaResponse = document.getElementById(‘recaptchaResponse’);
recaptchaResponse.value = token;
});
});
.grecaptcha-badge {
visibility: hidden;
}
grecaptcha.ready(function() {
grecaptcha.execute('ma_cle_secrete', { action: 'submit' }).then(function(token) {
var recaptchaResponse = document.getElementById('recaptchaResponse');
recaptchaResponse.value = token;
});
});
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!isset($_POST['g-recaptcha-response'])) {
die('reCAPTCHA manquant');
}
$recaptcha_secret = 'VOTRE_CLE_SECRETE';
$recaptcha_response = $_POST['g-recaptcha-response'];
$data = [
'secret' => $recaptcha_secret,
'response' => $recaptcha_response,
'remoteip' => $_SERVER['REMOTE_ADDR']
];
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
'timeout' => 5
]
];
$context = stream_context_create($options);
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context);
if ($response === false) {
die('Erreur lors de la vérification reCAPTCHA');
}
$result = json_decode($response, true);
if (empty($result['success'])) {
echo "reCAPTCHA verification failed.";
} else {
echo "reCAPTCHA verification successful.";
}
}