ReCaptcha invisible connection error

0

I'm first implementing an invisible google reCaptcha on a form. In the first tests reCaptcha worked correctly, but now it only appears a message of "Could not make contact with reCaptcha. Please check your connection and try again", and the form sends normally.

Here is the code used:

The index is like this

<form action="" class="form_contato">
    <div class="row">
       <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
           <input type="text" name="nome" placeholder="Nome">
        </div>
     </div>
     <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
           <input type="text" name="email" placeholder="E-mail">
        </div>
     </div>
     <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
           <input type="tel" name="telefone" placeholder="Telefone">
        </div>
     </div>
     <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <input type="text" name="assunto" placeholder="Assunto">
        </div>
     </div>
     <div class="row">
         <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <textarea name="mensagem" placeholder="Mensagem"></textarea>
         </div>
     </div>
     <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
           <div id='recaptcha' class="g-recaptcha"
           data-sitekey="minha chave"
           data-callback="onSubmit"
           data-size="invisible"></div>
           <input class="btn btn-enviar" type="submit" value="enviar">
        /div>
     </div>
 </form>

And in the footer

<script>
   function onSubmit(token) {
        $('.form_contato').submit();
   }
 </script>

And in php is as follows

if (isset($_POST['g-recaptcha-response'])) {
    $captcha_data = $_POST['g-recaptcha-response'];
}

//Secret key
$captcha_secret = "minha chave secreta";

// Se nenhum valor foi recebido, o usuário não realizou o captcha
if (!$captcha_data) {
    echo "Por favor, confirme o captcha.";
    exit;
}
$resposta = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$captcha_secret."&response=".$captcha_data."&remoteip=".$_SERVER['REMOTE_ADDR']);

if($resposta.success) {
  //meu código
} else {
    echo "Captcha incorreto";
}
    
asked by anonymous 27.03.2018 / 20:31

0 answers