为了账号安全,请及时绑定邮箱和手机立即绑定

reCAPTCHA V2 服务器端验证失败

reCAPTCHA V2 服务器端验证失败

PHP
qq_笑_17 2023-06-18 16:03:42
我的 reCaptcha V2“我不是机器人”在服务器端失败。它似乎失败了: post_captcha($_POST['g-recaptcha-response'])公钥和 pvt 密钥都是正确的,并且位于正确的域中。我创建 reCAPTCHA 已经 3 个小时了,所以通过系统处理我的域可能需要一些时间?我不知道....这是 HTML:<html><head>  <script src="https://www.google.com/recaptcha/api.js" async defer></script></head><body><form action="contact-form.php" method="POST">  <div class="g-recaptcha" data-sitekey="PUBLIC KEY"></div>  <br/>  <input type="submit" value="Submit"></form></body></html>这是PHP:<?php// Checks if form has been submittedif ($_SERVER['REQUEST_METHOD'] == 'POST') {    function post_captcha($user_response) {        $fields_string = '';        $fields = array(            'secret' => 'PVT KEY',            'response' => $user_response        );        foreach($fields as $key=>$value)        $fields_string .= $key . '=' . $value . '&';        $fields_string = rtrim($fields_string, '&');        $ch = curl_init();        curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');        curl_setopt($ch, CURLOPT_POST, count($fields));        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);        $result = curl_exec($ch);        curl_close($ch);        return json_decode($result, true);    }    // Call the function post_captcha    $res = post_captcha($_POST['g-recaptcha-response']);    if (!$res['success']) {        // What happens when the CAPTCHA wasn't checked        echo '<p>Please go back and make sure you check the security CAPTCHA box.</p><br>';    } else {        echo 'success';    }}?>任何帮助将不胜感激!谢谢。
查看完整描述

1 回答

?
Qyouu

TA贡献1786条经验 获得超11个赞

很久没有回答。问题是因为我的网络服务提供商对我订阅的共享服务器有限制,例如无法编辑 php.ini 配置文件。

解决方案:不要使用共享服务器!


查看完整回答
反对 回复 2023-06-18
  • 1 回答
  • 0 关注
  • 121 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信