doujiao4710 2019-05-04 01:14
浏览 215

验证时回收错误代码'connection-failed'

When implementing recaptcha v2, I am given the error code 'connection-failed' when trying to verify the recaptcha input.

I have followed this (https://www.freakyjolly.com/how-to-add-google-recaptcha-in-php-form/) tutorial as I had no luck with others that I found

    require('src/autoload.php');

    $siteKey = 'my key';
    $secret = 'my key';

    $recaptcha = new \ReCaptcha\ReCaptcha($secret);

    $gRecaptchaResponse = $_POST['g-recaptcha-response']; 
    $remoteIp = $_SERVER['REMOTE_ADDR']; 
    $recaptchaErrors = ''; 

    $resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);

    if ($resp->isSuccess()) {
        $error[] = "worked";
    } else {
        $recaptchaErrors = $resp->getErrorCodes(); 

        foreach($recaptchaErrors as $err)
        {
            $error[] = $err;
        }

    }

I have not had much luck finding any details on this error anywhere, and it is not documented on the official recaptcha page. I have edited the snippet above for testing purposes, but it would be sending an email.

  • 写回答

1条回答 默认 最新

  • doutu6658 2019-06-13 08:29
    关注

    I have had the same problem while working locally in a node environment running node-php-awesome-server. If you are trying to verify the reCaptcha response from localhost, with a localhost reCaptcha key pair, try from a live webserver (with relative key pair) instead. For some reason sending the request from localhost returned me that error. I suppose it has something to do with the development environment but did not investigate further.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大