2017-08-22 67 views
0

我在我的網站上使用重新驗證碼,但它不起作用,當我點擊登錄它說機器人驗證失敗,請再試一次我不知道如何解決它...每次:/我的重新驗證碼不工作

感謝您的幫助。

如果你有更好的腳本請寄給我。

 if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) 
    { 
     $secret = '**************'; 

     $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) 
     { 

     }else{ 
       echo "<div class='container'><div class='alert alert-danger'><p>Robot verification failed, please try again.</p></div>"; 
      } 
    }else{ 
      echo "<div class='container'><div class='alert alert-danger'><p>Please click on the reCAPTCHA box.</p></div>"; 
    } 
+0

你有以下答案;如果它解決了,你應該把它標記爲已解決。 「 –

+0

」不起作用「就意味着什麼,就像您幾分鐘前用相同的東西發佈(並刪除)的問題一樣;戒賭會遐嗎?並使用Stack作爲免費的調試服務。 –

回答

0

這裏是我如何處理谷歌驗證碼的服務器上:

//process captia response with a custom method. 
$captcha = checkCaptia($_POST['g-recaptcha-response']); 

if ($captcha){ 
    mailLead(); 
} 
else{ 
    header('location: https://...'); 
    die(); 
} 

方法來處理驗證碼檢查...

function checkCaptia($captcha){ 
    $url = 'https://www.google.com/recaptcha/api/siteverify'; 

    $data = array(
     'secret'=>';jaskdf;asdkjf', 
     'response'=>$captcha, 
     'remoteip'=>$_SERVER['REMOTE_ADDR'] 
    ); 

    $options = array(
     'http' => array(
     'header' => "Content-type: application/x-www-form-urlencoded\r\n", 
     'method' => 'POST', 
     'content' => http_build_query($data) 
     ) 
    ); 
    $context = stream_context_create($options); 
    $result = json_decode(file_get_contents($url, false, $context),TRUE); 

    return $result; 
}