weird reCaptcha error in PHP

人走茶凉 提交于 2020-01-16 01:49:04

问题


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.


回答1:


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;
}


来源:https://stackoverflow.com/questions/8603265/weird-recaptcha-error-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!