reCaptcha Google

-1

Hello. Well I have this code here. But I have a problem ... The reCaptcha appeared on my site, but the person can send the form even though I did not take 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 did not understand the reCaptcha API very well. Could anyone do it for me?

    
asked by anonymous 24.04.2018 / 05:37

1 answer

2

In your code there is only the verification of the name, which is a failure:

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

Your verification should look like this:

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

After verifying that the recaptcha information is complete, you must validate the received json. Here is sample code available at CodexWorld , which illustrates how it should be done all validation:

<?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.
    }
}
?>
    
24.04.2018 / 15:00