php中的Google recaptcha v2验证-空响应

问题描述 投票:0回答:1

在过去的几个月中,我一直在许多php网站上使用recaptcha v2。最近他们都停止工作了。管理员页面显示“我们检测到您的站点未在验证reCAPTCHA解决方案”。这次我没有更改任何代码,因此可以确定问题不在于此,并且可以看到我仍在成功捕获用户响应,但是我对如何获取表格感到困惑。再次工作。我曾尝试为其中一个站点重新创建新密钥,但这没什么区别。其他人有没有经历过?这是我正在使用的相关验证码...

    if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $secretKey = 'the-key-I-was-given';
    $captcha = $_POST['g-recaptcha-response'];

    if(!$captcha){
      header('Location: nocheck.html');
      exit;
    }

    $mail_to = "my-email-address";
    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $message = $_POST['message'];

    $email_from = $_POST['email'];
    $subject = "Message from ....";
    $email_body = "You have received a new message from $name.\n".
     "Here is the message:\n\n $message\n\n";

    if ( empty($email_from) OR !filter_var($email_from, FILTER_VALIDATE_EMAIL) OR empty($subject) OR empty($email_body)) {
        http_response_code(400);
        echo '<p class="alert alert-warning">Please complete all fields on the form and try again.</p>';
        exit;
    }

    $ip = $_SERVER['REMOTE_ADDR'];
    $responsedata=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
    $responseKeys = json_decode($responsedata,true);

    if(intval($responseKeys["success"]) !== 1) {
      echo '<p class="alert alert-warning">Oops! Captcha verification has failed. Please email me instead at my-email-address. Thank you.</p>';
    } else {

响应似乎每次都是0-因此触发验证失败错误。任何指针表示感谢,谢谢。

php recaptcha
1个回答
0
投票

我有类似的问题。我两周前更换了主机,并且相同的ReCAPTCHA代码不再起作用。我还在Recaptcha管理控制台中收到相同的消息:“我们检测到您的站点未在验证reCAPTCHA解决方案。这是在站点上正确使用reCAPTCHA所必需的。请参阅我们的developer site了解更多信息。”

我认为与Google Developers的链接很重要,但我无法执行该怎么做。您(标记)正在从服务器下载错误日志吗?每次ReCaptcha失败后,它都会在根文件夹中生成。我通过FTP下载并阅读了最新的错误。我经常遇到以下5个错误。

[12-Jan-2020] Error 1: PHP Warning:  require_once(cgi-bin/ReCaptcha.php): failed to open stream: No such file or directory in /public_html/submit2.php on line 2

我:我以为我的文件路径错误,但是我更改了它们,但没有任何反应,我想我会再试一次。即Ln 2:require_once('cgi-bin / ReCaptcha.php');变成Ln 2:require_once('/ cgi-bin / ReCaptcha.php');没用。

[[2020年1月12日]错误2:PHP致命错误:require_once():无法打开所需的'cgi-bin / ReCaptcha.php'(include_path ='。:: / opt / cpanel / ea-php72 / root / usr / share_pear')在第2行的/public_html/submit2.php中我:不知道为什么要在那里看?上面的示例是Submit2.php的第2行。

[[2020年1月13日00:00:55 UTC]错误3:PHP警告:file_get_contents():在服务器配置中,通过/ public_html / cgi-bin / Post中的allow_url_fopen = 0禁用了https://包装器。第68行的php我:Post.php的68行显示:返回file_get_contents(self :: SITE_VERIFY_URL,false,$ context);04FS提到了allow_url_fopen,但我不知道他的意思。

[[13-Jan-2020 00:00:55 UTC]错误4:PHP警告:file_get_contents(https://www.google.com/recaptcha/api/siteverify):无法打开流:在/public_html/cgi-bin/Post.php中找不到合适的包装器在第68行我:第68行...

[[2020年1月14日02:53:18 UTC]错误5:PHP解析错误:语法错误,第11行的/public_html/submit2.php中出现意外的'$ secret'(T_VARIABLE)我:这是我的错误-密钥(在我今天做了新密钥之后)后缺少分号,但在修复后也失败了。

我希望这会有所帮助,如果不能,对不起。如果可以使用,我会再次发布。

© www.soinside.com 2019 - 2024. All rights reserved.