douzhang1364 2014-03-26 19:49 采纳率: 0%
浏览 321

当reCaptcha输入正确时,代码无效

I am trying to implement Google's reCaptcha on my website's query form in php.

When the CAPTCHA is entered incorrectly,
I get: "No. CAPTCHA is not entered correctly".

But when the CAPTCHA is entered correctly,
What I expect: "Everything looks good" OR "CAPTCHA is correct but other values are incorrect."
What I get: Blank Page

Here is how I am implementing it:

$var1 = $_POST["var1"];
$var2 = $_POST["var2"];

require_once('recaptchalib.php');
    $privatekey = "<private key I got from reCaptcha>";
    $respCaptcha = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

if(!$respCaptcha->is_valid) {
    echo "No. CAPTCHA is not entered correctly";

} elseif(    is_numeric($var1) 
          && preg_match("/^[a-zA-Z ]*$/",$var2)) {        
    echo "Everything looks good";

} else {

    echo "CAPTCHA is correct but other values are incorrect.";

}

Please help. What am I doing wrong here?

  • 写回答

1条回答 默认 最新

  • duanjian3338 2014-03-26 19:56
    关注

    Try putting the if just inside the else...

    Also is this directly pasted because the line

    'Do something...' is not commented
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端