3

在 recaptcha 的文档(https://developers.google.com/recaptcha/docs/verify)中,它说 remoteip 参数是可选的,但我试图在请求中发送一个硬编码的错误 IP,但谷歌仍然返回一个成功:真响应。此参数的全部目的是防止使用第三方应用程序或工作人员(例如点击农场)生成的重新验证令牌,然后注入到表单提交中。

老实说,我看不出我的代码有什么问题。如果有人知道此功能是否已被 Google 删除,请告诉我。

这是以前在这里提出的,但回答的人并不理解用户很难理解的问题:Google recaptcha remoteip 解释

您可以通过在此处创建 reCAPTCHA v2 并替换 SITEKEY_GOES_HERE 和 SECRET_HERE 来自行测试:https: //www.google.com/recaptcha/admin

{ "success": true, "challenge_ts": "2020-05-18T02:48:33Z", "hostname": "########" }

这是我的 verify.php 代码:

<?php
    $sender_name = stripslashes($_POST["sender_name"]);
    $sender_email = stripslashes($_POST["sender_email"]);
    $sender_message = stripslashes($_POST["sender_message"]);
    $response = $_POST["g-recaptcha-response"];

    $url = 'https://www.google.com/recaptcha/api/siteverify';
    $data = array(
        'secret' => 'SECRET_HERE',
        'response' => $_POST["g-recaptcha-response"],
        'remoteip' => '123.123.123.123',
    );
    $options = array(
        'http' => array (
            'method' => 'POST',
            'content' => http_build_query($data)
        )
    );
    $context  = stream_context_create($options);
    $verify = file_get_contents($url, false, $context);
    $captcha_success=json_decode($verify);

    if ($captcha_success->success==false) {
        echo $verify;
    } else if ($captcha_success->success==true) {
        echo $verify;
    }
?>

这是我的 index.html 代码:

<html>
  <head>
    <title>reCAPTCHA demo: Simple page</title>
    <script src="https://www.google.com/recaptcha/api.js" async defer></script>



  </head>
  <body>

  <form action="verify.php" method="post" enctype="multipart/form-data">
    <input name="sender_name" placeholder="Your Name..."/>
    <input name="sender_email" placeholder="Your email..."/>
    <textarea placeholder="Your Message..." name="sender_message"></textarea>
        <div class="captcha_wrapper">
        <div class="g-recaptcha" data-sitekey="SITEKEY_GOES_HERE"></div>
    </div>
    <button type="submit" id="send_message">Send Message!</button>
</form>


  </body>
</html>

是的

4

0 回答 0