本文介绍了PHP中奇怪的reCaptcha错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上执行reCaptcha时遇到了问题。



我在这里跟着教程:,并且实现了一个基本的reCaptcha,带有错误消息。



以下是我在提交表单的文件中使用的一些自定义代码:



<$ p $如果(!$ resp-> isValid){
$ _SESSION ['badLoginCount'] + = 1; p>
$ _SESSION ['incorrect-captcha'] = true;
$ _SESSION ['incorrect-captcha-error'] = $ resp->错误;
header('Location:../../signin.php');
出口;





$ b如果用户键入不正确的reCaptcha,页面会重定向并显示错误如预期。但是,当用户输入正确的reCaptcha时,isValid仍然评估为FALSE并运行此分支,但$ resp-> error不包含任何内容,这使得调试几乎不可能。



有没有人遇到过这个?我无法在网上找到任何东西。

解决方案

一个快速而且有效的解决方法是检查 $

  if(!empty($ resp-> error 错误)){
$ _SESSION ['badLoginCount'] + = 1;
$ _SESSION ['incorrect-captcha'] = true;
$ _SESSION ['incorrect-captcha-error'] = $ resp->错误;
header('Location:../../signin.php');
出口;
}


I am having a problem with implementing a reCaptcha on my website.

I followed the tutorial here: http://code.google.com/apis/recaptcha/docs/php.html and implemented just a basic reCaptcha with an error message.

Below is some custom code I use in the file which the form is submitted to:

    if (!$resp->isValid) {
        $_SESSION['badLoginCount'] += 1;
        $_SESSION['incorrect-captcha'] = true;
        $_SESSION['incorrect-captcha-error'] = $resp->error;
        header ('Location: ../../signin.php');
        exit;
    }

If the user types the incorrect reCaptcha, the page redirects and an error is shown as expected. However when a user enters the correct reCaptcha, isValid still evaluates to FALSE and runs this branch, however $resp->error contains nothing, and this has made it almost impossible to debug.

Has anyone come across this before? I can't find anything online.

解决方案

A quick and hacky workaround would be to check if $resp->error is empty instead.

if (!empty($resp->error)) {
    $_SESSION['badLoginCount'] += 1;
    $_SESSION['incorrect-captcha'] = true;
    $_SESSION['incorrect-captcha-error'] = $resp->error;
    header ('Location: ../../signin.php');
    exit;
}

这篇关于PHP中奇怪的reCaptcha错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 10:21