I have a problem with Recaptcha V3. I am almost alway's getting a negative score. I tested it from someone else's mobile device and he got a score of 0.3.
Now i have if ($captchaResponse['success'] == '1' && $captchaResponse['score'] >= 0.1) {
activated on all websites. Normally this is at 0.5. Nobody can login in my website without getting a negative score. Am i doing something wrong?
This is the rest of my PHP code:
$response = $_POST['token'];
// get cURL resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, 'https://www.recaptcha.net/recaptcha/api/siteverify');
// set method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// set headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
]);
// form body
$body = [
'secret' => 'SECRET_KEY',
'response' => $response,
];
$body = http_build_query($body);
// set body
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
// send the request and save response to $response
$response = curl_exec($ch);
$captchaResponse = json_decode($response, true);
And here is the Jquery code:
$(document).ready(function(){ $(".recaptcha_form").on("submit", function(e){
e.preventDefault();
//recaptcha token code
grecaptcha.ready(function() {
grecaptcha.execute('<?php echo RECAPTCHA_SITE_KEY; ?>', {action: 'homepage'}).then(function(token) {
$('#token').val(token);
$('#tokenPendingPage').val(token);
$('#tokenAccount-account-overview').val(token);
$('#tokenChangePasswordAfterLogin').val(token);
$('#tokenRegisterCheckout').val(token);
});
});
});
});
Maybe because i do this below (refreshing token every 3 seconds):
function loadCaptcha() {
grecaptcha.ready(function() {
grecaptcha.execute('<?php echo RECAPTCHA_SITE_KEY; ?>', {action: 'homepage'}).then(function(token) {
$('#token').val(token);
$('#tokenLoginHeader').val(token);
$('#tokenPendingPage').val(token);
$('#tokenAccount-account-overview').val(token);
$('#tokenChangePasswordAfterLogin').val(token);
$('#tokenRegisterCheckout').val(token);
});
});
}
function loadCaptcha2() {
grecaptcha.ready(function() {
grecaptcha.execute('<?php echo RECAPTCHA_SITE_KEY; ?>', {action: 'homepage'}).then(function(token) {
$('#tokenLoginHeader').val(token);
});
});
}
// Refresh token recaptcha every 3 seconds
$(document).ready(function() {
console.log('xxx');
loadCaptcha2();
setTimeout(function() {
loadCaptcha2();
setInterval(loadCaptcha, 105 * 1000); // fire every 10 sec
}, 90 * 1000); // fire only one time after 10 sec
});