I
I
Ivan Ivanovich2019-12-18 18:01:11
PHP
Ivan Ivanovich, 2019-12-18 18:01:11

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();
    }

Did I do the sequence correctly?
I mean that it may be necessary to do the getCaptcha function right away right away, and everything else later.
Could this be the reason?
Thanks in advance

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question