2016-02-19 77 views
0

我有一個奇怪的問題,谷歌驗證碼。我已經試過各種不同的教程PHP代碼,但結果是完全一樣的,每次...谷歌nocaptcha奇怪的事

問題是這樣的:

  • 它顯示了正確
  • 如果你檢查盒子,它工作正常
  • ,如果你再發送的形式,它工作正常
  • 但是...如果你選中該複選框,形式仍發送!

所以,換句話說,它只是在形式上作爲裝飾件。可能是什麼問題呢?這可能很簡單,但我完全錯過了它。

幫助或見解非常感謝!提前致謝!

附錄

下面是與我所使用的模板傳來代碼:

require_once('recaptcha-php-1.11/recaptchalib.php'); 

if ($use_captcha == 1) { 

$resp = null; 
$error = null; 
$reCaptcha = new ReCaptcha($secret); 
$secret = "MY SECRET KEY HERE"; 
$captcha_error_message = '<div class="pi-alert-danger fade in"><button type="button" class="pi-close" data-dismiss="alert"><i class="icon-cancel"></i></button><p>Bewijs dat je geen robot bent!</p></div>'; 

if (isset($_POST["captcha_response"]) && $_POST["captcha_response"] != '') { 

    $resp = $reCaptcha->verifyResponse(
     $_SERVER["REMOTE_ADDR"], 
     $_POST["captcha_response"] 
    ); 

    if ($resp && $resp->success != true) { 
     echo $captcha_error_message; 
     exit(); 
    } 

} else { 
    echo $captcha_error_message; 
    exit(); 
} 

} 
+1

代碼示例將是helful。在提交期間是否放置了任何複選框驗證? – mitkosoft

+0

我可能是錯的,但驗證碼的目的不是要阻止提交表單,而是讓您在接收服務器端的數據時驗證它是由人類提交的。 –

+0

添加了相關標籤。 – maxhb

回答

0

你必須檢查驗證碼得到解決(在你的PHP腳本里面做任何形式的數據)

喜歡這個:

function checkCaptcha($recaptchaResponse) { 
    $recaptchaPrivateKey = 'Your Private Key'; 

    if(! $recaptchaResponse) 
     return false; 

    $recaptchaObj = new ReCaptcha($recaptchaPrivateKey); 
    $response = $recaptchaObj->verifyResponse($_SERVER["REMOTE_ADDR"], $recaptchaResponse); 

    if($response != null && $response->success) 
     return true; 

    return false; 
} 

如果你沒有在你的表單函數中包含這樣的函數,你的服務器會說,表單沒問題,因爲它不知道驗證碼。

請注意,您還必須包含Google驗證碼Libarys-File。你可以在這裏找到它: https://github.com/google/recaptcha/blob/1.0.0/php/recaptchalib.php(工作NoCaptcha以及)

+0

感謝您的回覆!我嘗試了你提供的代碼,但不幸的是它沒有工作。 –