2017-03-16 4 views
2

그래서 Google에서는 일부 웹 사이트에 Google의 새로운 Invisible reCaptcha를 구현하려고합니다.누락 입력 응답 | Invisible reCaptcha

정확하게 단계를 따르고 있지만 지속적으로 누락 된 입력 응답 오류가 발생합니다.

HTML 코드 :

<form id="subscribe-form" class="form-inline" action="phpScripts/subscribe/subscribeHandler.php" method="post"> 
    <div class="input-group"> 
     <input type="email" name="email" class="form-control" size="50" placeholder="Email Address" required> 
     <div class="input-group-btn"> 
      <button class="g-recaptcha btn btn-danger" data-sitekey="6LfoNhkUAAAAAEcQFx8vGHZKHXsZ_q0j2KDnmU9M" data-callback="submitForm">Subscribe</button> 
     </div> 
    </div> 
</form> 

PHP 코드 : 그래서

<?php 
include 'databaseConnection.php'; 
if($_POST){ 
      $secret = "MY SECRET KEY"; 
      $captcha= $_POST['g-recaptcha-response']; 
      $ip = $_SERVER['REMOTE_ADDR']; 
      $url= file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$captcha&remoteip=$ip"); 
      print_r($url); 
      $decodedResponse = json_decode($url, TRUE); 

      if($decodedResponse['success'] == 1){//code here} 

, 나는 생각하고 나의 $의 보안 문자 변수 g-reCAPTCHA를 응답의 POST에서하지 "캐치"아무것도 할 수 있습니다. 그러나 이것이 왜 Google이 말하는지와 이전 reCaptcha v2와 정확히 똑같습니다.

Aswell는, 나는 당신이 가능하게 버튼에 기능을 묶는 것 일 수 있었다

답변

1

문제 <script src='https://www.google.com/recaptcha/api.js'></script>을 포함했다.

당신의 키를 생성 할 때 그들이 당신을주는 코드 실행하십시오 :

는 PHP 로직 검증을위한
<form id="subscribe-form" class="form-inline" action="phpScripts/subscribe/subscribeHandler.php" method="post"> 
    <div class="input-group"> 
     <input type="email" name="email" class="form-control" size="50" placeholder="Email Address" required> 
     <div class="g-recaptcha" data-sitekey="{keyhere}"></div> 
     <div class="input-group-btn"> 
      <button class="btn btn-danger" data-sitekey=" data-callback="submitForm">Subscribe</button> 
     </div> 
    </div> 
</form> 

:

if ($_POST['g-recaptcha-response']) { 
$secret = '{keyhere}'; 
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secret . "&response=" . $_POST['g-recaptcha-response'] . "&remoteip=" . $_SERVER['REMOTE_ADDR']); 
     $response = json_decode($response); 
     if (! $response->success) { 
      //return error 
     } 

     //code logic below 
} 

키를 만들 때 제공 DIV 코드가 제대로을 모두 생성한다을 양식을 제출할 때 PHP 유효성 검사를 통해 처리 할 수 ​​있도록 HTML이 필요합니다.

1

다음은 해결책입니다.

  • 클라이언트 측
<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>reCaptcha</title> 

    <!--api link--> 
    <script src="https://www.google.com/recaptcha/api.js" async defer></script> 
    <!--call back function--> 
    <script> 
     function onSubmit(token) { 
      document.getElementById('reCaptchaForm').submit(); 
     } 
    </script> 
</head> 
<body> 
<div class="container"> 
    <form id="reCaptchaForm" action="signup.php" method="POST"> 
     <input type="text" placeholder="type anything"> 
     <!--Invisible reCaptcha configuration--> 
     <button class="g-recaptcha" data-sitekey="<your site key>" data-callback='onSubmit'>Submit</button> 
     <br/> 
    </form> 
</div> 
</body> 
</html> 
  • 서버 측 유효성 검사 :하는 signup.php 파일
몇 시간 동안
<?php 
//only run when form is submitted 
if(isset($_POST['g-recaptcha-response'])) { 
    $secretKey = '<your secret key>'; 
    $response = $_POST['g-recaptcha-response'];  
    $remoteIp = $_SERVER['REMOTE_ADDR']; 


    $reCaptchaValidationUrl = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$response&remoteip=$remoteIp"); 
    $result = json_decode($reCaptchaValidationUrl, TRUE); 

    //get response along side with all results 
    print_r($result); 

    if($result['success'] == 1) { 
     //True - What happens when user is verified 
     $userMessage = '<div>Success: you\'ve made it :)</div>'; 
    } else { 
     //False - What happens when user is not verified 
     $userMessage = '<div>Fail: please try again :(</div>'; 
    } 
} 
?> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="UTF-8"> 
     <title>reCAPTCHA Response</title> 
    </head> 
    <body> 
     <?php 
      if(!empty($userMessage)) { 
       echo $userMessage; 
      } 
     ?> 
    </body> 
</html> 
4
저도 같은 문제에 직면했다

만들기 내가 마침내 그 논리를 이해할 때까지 이 "보이지 않는 captcha"! g-recaptcha-response

이 텍스트 영역은 정상적으로 발생 도전이 완료된 후 응답 문자열 (로 채워의 ID와 이름이 빈 텍스트 영역 요소가 있기 때문에 당신이 응답을하지 않는 이유는 단순히 "recurscha")하지만 "invisible-captcha"의 경우 grecaptcha.execute();을 "submit"버튼으로 명시 적으로 호출해야합니다. 그러면 텍스트 영역이 채워지고 양식이 자동으로 제출됩니다 (사용자가 callback 함수를 사용하여 제출을 제한 한 경우).

필자는 이미 PHP에서 폼을 처리하고 유효성 검사를 recaptcha로 수행하므로 이전 버전의 "checkbox"(적어도 개선 될 때까지)를 유지하기로 결정했습니다. 모든 것을 변경하는 것이 정말 짜증나기 때문입니다. (폼 제출 로직, 버튼 액션 및 자바 스크립트 코드) 확인란을 숨기려면! 특히 두 방법 모두 거의 동일합니다!