reCaptcha Google

Asked

Viewed 705 times

-1

Hello. Well, I got this code right here. But I have a problem... reCaptcha appeared on my website, but the person can send the form even if they have not done the Captcha step...

<form action="" method="post" name="power" id="power">
   <p class="contato-aviso">Os campos com <b>"*"</b> são obrigatórios!!</p>
   <div class="form-group row">
      <div class="col-sm-3"> 
         <label for="nome">Nome<b style="color: red; font-size: 13px;">*</b></label> 
      </div>
      <div class="col-9"> 
         <input  class="form-control" name="nome" type="text" id="nome" placeholder="Nome Completo" required> 
      </div>
   </div>
   <div class="form-group row">
      <div class="col-sm-3"> 
         <label for="facebook">Facebook</label> 
      </div>
      <div class="col-9"> 
         <input  class="form-control" name="facebook" type="text" id="facebook" placeholder="Link do Perfil no Facebook"> 
      </div>
   </div>
   <div class="form-group row">
      <div class="col-sm-3"> 
         <label for="skype">Skype</label> 
      </div>
      <div class="col-9"> 
         <input  class="form-control" name="skype" type="text" id="skype" placeholder="Contato Skype"> 
      </div>
   </div>
   <div class="form-group row">
      <div class="col-sm-3"> 
         <label for="discord">Discord</label> 
      </div>
      <div class="col-9"> 
         <input  class="form-control" name="discord" type="text" id="discord" placeholder="Contato Discord"> 
      </div>
   </div>
   <div class="form-group row">
      <div class="col-sm-3"> 
         <label for="assunto">Assunto<b style="color: red; font-size: 13px;">*</b></label> 
      </div>
      <div class="col-9"> 
         <input  class="form-control" name="assunto" type="text" id="assunto" placeholder="Assunto"  required> 
      </div>
   </div>
   <div class="form-group row">
      <div class="col-3"> 
         <label for="email">Email<b style="color: red; font-size: 13px;">*</b></label> 
      </div>
      <div class="col-9"> 
         <input class="form-control" name="email" type="email" id="email" placeholder="E-mail"  maxlength="40" required>
      </div>
   </div>
   <div class="form-group row">
      <div class="col-3"> 
         <label for="mensagem">Mensagem<b style="color: red; font-size: 13px;">*</b></label> 
      </div>
      <div class="col-9"> 
         <textarea class="form-control" name="mensagem" id="mensagem" placeholder="Sua Mensagem"  rows="5" required></textarea>
      </div>
   </div>
   <center>
      <div name="grecaptcha" id="grecaptcha"  class="g-recaptcha" data-sitekey="6LfFGFUUAAAAAI3s5OAuRlm1IVUaLrf31mjBwGkh" required></div>
   </center>
   <input name="Send" class="button-contato" type="submit" id="Send" value="Enviar" required>
   <br> <br> 
   <input name="Clear" class="button-contato" type="reset" id="Clear" value="Limpar">
   <?php
      if (isset($_POST[nome])){
      $nome =   $_POST[nome];
      $facebook =   $_POST[facebook];
      $skype =   $_POST[skype];
      $discord =   $_POST[discord];
      $email =  $_POST[email];
      $mensagem = $_POST[mensagem];
      $grecaptcha = $_POST[grecaptcha];
      $assunto = "$_POST[nome], esta entrando em contato com voce.     Assunto: $_POST[assunto]";

        $send = ("$email_01"); //Coloque seu E-mail aqui.

        $data = date("d/m/y");     
        $hora = date("H:i:s");
        $ip = $_SERVER[REMOTE_ADDR];

        $headers .= "From: $send\r\n"; 
                                //para o envio em formato HTML
                                $headers = "MIME-Version: 1.0\r\n";
                                $headers .= "Content-type: text/html;
                                charset=iso-8859-1\r\n";

                                $corpo =("
                                            <b style=\"color:#000; font-size: 18px; font-weight: 600;\">Nome Completo:  </b> <b style=\"color:#000; font-size: 16px;font-weight: 500;\"> $nome</b>
                                            <br>
                                            <b style=\"color:#000; font-size: 18px; font-weight: 600;\">Perfil Facebook:  </b> <a href=\"$facebook\" style=\"color:#000; font-size: 16px;font-weight: 500;\">$facebook<a/>
                                            <br>
                                            <b style=\"color:#000; font-size: 18px; font-weight: 600;\">Contato Skype:  </b> <b style=\"color:#000; font-size: 16px;font-weight: 500;\"> $skype </b>
                                            <br>
                                            <b style=\"color:#000; font-size: 18px; font-weight: 600;\">Contato Discord:  </b> <b style=\"color:#000; font-size: 16px;font-weight: 500;\"> $discord </b>
                                            <br>
                                            <b style=\"color:#000; font-size: 18px; font-weight: 600;\">E-Mail:  </b> <b style=\"color:#000; font-size: 16px;font-weight: 500;\"> $email</b>
                                            <br><br>
                                            <hr/>
                                            <b style=\"color:#000; font-size: 18px; font-weight: 600;\">Mensagem:  </b> <br> <b style=\"color:#000; font-size: 16px;font-weight: 500;\"> $mensagem</b>
                                            <hr/>
                                            <br><br>



                                            <b style=\"color:red; font-size: 15px; font-weight: 600;\">  Data:   $data  <br/></b>
                                            <b style=\"color:red; font-size: 15px; font-weight: 600;\">  Hora:   $hora  <br/></b>
                                            <b style=\"color:red; font-size: 15px; font-weight: 600;\">  IP:   $ip  <br/></b>

                                            ");

                                    mail($send, $assunto, $corpo, $headers); 

                                echo "<script type=\"text/javascript\"> alert('$nome, Obrigado por entrar em contato comigo !!               Logo mais entrarei em contato com você. Caso deseja um contato mais rapido, me chame pelas redes sociais. Grato !') </script>";


      } else{


      }

       ?>
</form>

I didn’t understand the reCaptcha API very well. Someone could do it for me ?

  • reCaptcha will pass you a key, which you will validate in Google’s webservice, using PHP

  • If the user does not perform captcha, the value passed by the form will be null. If reCaptcha loses validity, when checking in PHP, it will emit an error.

  • @Sveen that I understood. What I am not able to do and what, the person pass the form doing it

  • Related: https://answall.com/q/268143/8063

  • You’re just checking the name if (isset($_POST[nome])){, has to check the recaptcha as well

1 answer

2

Your code only checks the name, which is a flaw:

if (isset($_POST[nome])){

Your verification should follow this way:

if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):

After checking if there is the information of the completed recaptcha must validate the received json. Follow example code available on the site Codexworld (adapted), which illustrates how all the validation should be done:

<?php
if(isset($_POST['submit']) && !empty($_POST['submit']))
{
    if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response']))
    {
        //your site secret key
        $secret = '9LuDh9kyetYYYYdTXXXXXXXXXXXXXXXXX';
        //get verify response data
        $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
        $responseData = json_decode($verifyResponse);
        if($responseData->success)
        {
            //SEU CODIGO AQUI
        } else {
            //ERRO: Robot verification failed, please try again.
        }
    } else {
        //ERRO: Please click on the reCAPTCHA box.
    }
}
?>
  • I still can’t do it...

  • Please give details of what is occurring, I have no help without knowing the problem.

  • Fernando, the code didn’t work... ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.