Not a stable job google captcha?

Hello.

Have installed Google Recaptcha v3.

And when you test on your local hosting, everything works fine, but in reality constantly considers the user as a robot, always.

I thought that may be the case in your 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 'Enter a name';
exit();
 } else if(mb_strlen($username) < 2){
 echo 'Enter more words';
exit();
 } else if(mb_strlen($username) > 55){
 echo 'Too many characters';
exit();
}

 $sql = 'INSERT INTO tasks(username) VALUES(:username)';
 $query = $pdo->prepare($sql);
 $query->execute(['username' => $username]);
}
else{
 header('Location: robot.html');
exit();
 }


If I made the right sequence?

I mean, it may be necessary function getCaptcha right away right to do, and then everything else.

Could this be the reason?

Thanks in advance
April 3rd 20 at 18:34
1 answer
April 3rd 20 at 18:36
Solution
If you tested work the captcha and filled in the hosting hasn't changed the keys, it is better to change them. Had a similar problem with this.
@juvenal.Ada And how can you change the keys? Do not tell me? - izabella_Hintz2 commented on April 3rd 20 at 18:39
In the admin console the captcha, then in the code accordingly. You may have to delete the old setting and create a new one. - juvenal.Ada commented on April 3rd 20 at 18:42
@juvenal.Ada, i.e., to remove the captcha and create a new similar can be? - izabella_Hintz2 commented on April 3rd 20 at 18:45
@juvenal.Ada, I'm just the admin console not found the possibility to change the keys - izabella_Hintz2 commented on April 3rd 20 at 18:48
@izabella_Hintz2, yeah, why not. Only domains is correct to prescribe - juvenal.Ada commented on April 3rd 20 at 18:51
@juvenal.Ada, I heard for a local test can local path to the file to register, don't know if so? - izabella_Hintz2 commented on April 3rd 20 at 18:54
What file? To register domains localhost and 127.0.0.1 for local tests - juvenal.Ada commented on April 3rd 20 at 18:57
@juvenal.Ada, did Not help to recreate the keys - izabella_Hintz2 commented on April 3rd 20 at 19:00
Evaluation gives not the expected or the condition is not work out? - juvenal.Ada commented on April 3rd 20 at 19:03
@juvenal.Ada,
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']);
var_dump($Return);
 if($Return->success == true && $Return->score > 0.5){
 echo "person";
}
 else {
 echo "the robot";
 }


returns null - izabella_Hintz2 commented on April 3rd 20 at 19:06
@juvenal.Ada, Everything was decided by itself 0_o apparently Google is naughty - izabella_Hintz2 commented on April 3rd 20 at 19:09

Find more questions by tags PHPCAPTCHAreCAPTCHA