Answer the question
In order to leave comments, you need to log in
Not stable work of google captcha?
Hello.
Installed Google Recaptcha v3.
And when testing on local hosting, everything works fine, but on real hosting it constantly considers the user to be a robot, always.
I thought it might be in the code.
define('SITE_KEY', '');
define('SECRET_KEY', '');
require 'db.php';
$username = $_POST['username'];
function getCaptcha($SecretKey) {
$Response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".SECRET_KEY."&response={$SecretKey}");
$Return = json_decode($Response);
return $Return;
}
$Return = getCaptcha($_POST['g-recaptcha-response']);
if($Return->success == true && $Return->score > 0.5){
$username = strip_tags($username);
$username = htmlspecialchars($username);
if ($username == '') {
echo 'Введите имя';
exit();
} else if(mb_strlen($username) < 2){
echo 'Введите больше слов';
exit();
} else if(mb_strlen($username) > 55){
echo 'Слишком много символов';
exit();
}
$sql = 'INSERT INTO tasks(username) VALUES(:username)';
$query = $pdo->prepare($sql);
$query->execute(['username' => $username]);
}
else{
header('Location: robot.html');
exit();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question