【问题标题】:How to reset Google reCaptcha?如何重置谷歌验证码?
【发布时间】:2018-01-22 01:33:55
【问题描述】:

这是我的 PHP 代码:

    function post_captcha($user_response) {
    $fields_string = '';
    $fields = array(
        'secret' => '',
        '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);
}
$res = post_captcha($_POST['g-recaptcha-response']);
if (!$res['success']) {
      die('MF005');
} else {
if ($mail->send()) { 
$send_arEmail = $autoresponder->Send();
}}

这是我的 JavaScript 代码:

<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmit(token) {
    document.getElementById("i-recaptcha").submit();
}
</script>

这是我的验证码:

<div class="g-recaptcha" data-sitekey="" ></div>

这是按钮提交:

<button class="button rounded" type="submit" data-callback="onSubmit">Send</button>

这也是我的表单 ID:

<form id="i-recaptcha">

**

上面的这个功能是有效的,但是在提交表单后,仍然是验证码 已选中,一旦用户单击提交,我想将其重置为未选中 按钮。

**

提前致谢

【问题讨论】:

  • 詹姆斯运气好吗?

标签: javascript php recaptcha invisible-recaptcha


【解决方案1】:

你可以这样使用它。它基于版本。

第 3 版

grecaptcha.ready(function() {
    grecaptcha.execute('SITE_KEY', {action: 'homepage'}).then(function(token){
        $('#token').val(token);
    });
});

第 2 版

grecaptcha.reset();

版本 1

Recaptcha.reload();

【讨论】:

  • 我已经添加了这两个 JavaScript 但它不起作用。如何添加?
  • 你用的是哪个版本?
  • 不知道是哪个版本,可以看我上面的代码。请给我一个解决方案。谢谢
  • @Zam85 我认为这个 grecaptcha.reset();可以为你工作。
  • @Zam85 请访问developers.google.com/recaptcha/docs/faq#blocked_frame 了解有关 v2 与 v3 的更多信息。
猜你喜欢
  • 1970-01-01
  • 2012-03-02
  • 2016-07-07
  • 1970-01-01
  • 1970-01-01
  • 2019-07-18
  • 2017-01-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多