谷歌nocaptcha的奇怪之处

时间:2016-02-19 11:28:59

标签: php html recaptcha

我对Google Captcha有一个奇怪的问题。我尝试过不同教程的各种PHP代码,但每次结果都完全一样......

问题在于:

  • 显示正确
  • 如果您选中此框,则表明其正常运行
  • 如果您然后发送表格,它可以正常工作
  • 但是......如果你选中该框,表格仍然会被发送!

因此,换句话说,它只是作为装饰品的形式。可能是什么问题呢?这可能是非常简单的事情,但我完全错过了它。

非常感谢帮助或见解!提前谢谢!

附录

以下是我使用的模板附带的代码:

    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 个答案:

答案 0 :(得分: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-captcha Libarys-File。你可以在这里找到它: https://github.com/google/recaptcha/blob/1.0.0/php/recaptchalib.php(也为NoCaptcha工作)