gpt4 book ai didi

javascript - Google reCAPTCHA V2 JavaScript 我们检测到您的站点未验证 reCAPTCHA 解决方案

转载 作者:可可西里 更新时间:2023-10-31 22:50:38 26 4
gpt4 key购买 nike

错误信息我们检测到您的站点未验证 reCAPTCHA 解决方案。这是在您的网站上正确使用 reCAPTCHA 所必需的。请查看我们的开发者网站了解更多信息。我创建了这个 reCaptcha 代码,它运行良好但我不知道如何验证它,我认为它正在使用函数进行验证grecaptcha.getResponse(); 但事实并非如此。显然,recaptcha 在网站上运行良好,但我刚刚在 Google 管理员中看到了下一条消息: enter image description here

要求:1.不要在表单中使用action="file.php",只在表单中使用javascript函数。

     <!DOCTYPE>
<html>
<head >
<title></title>
<script src='https://www.google.com/recaptcha/api.js'></script>
<script type="text/javascript">
function get_action() {
var v = grecaptcha.getResponse();
console.log("Resp" + v );
if (v == '') {
document.getElementById('captcha').innerHTML = "You can't leave Captcha Code empty";
return false;
}
else {
document.getElementById('captcha').innerHTML = "Captcha completed";
return true;
}
}
</script>
</head>
<body>
<form id="form1" onsubmit="return get_action();">
<div>
<div class="g-recaptcha" data-sitekey="6LdNIlAUAAAAADS_uVMUayu5Z8C0tw_jspdntbYl"></div>
</div>
<input type="submit" value="Button" />

<div id="captcha"></div>
</form>
</body>
</html>

请你帮帮我。我会很感激我如何验证它,因为我需要使用 javascript 函数 onsubmit="return get_action();" 而不是 action="file.php" *当我提交时? :

最佳答案

grecaptcha.getResponse() 函数只会为您提供用户响应 token ,然后必须在 google reCAPTCHA 服务器上通过 HTTP POST 调用对其进行验证。

您可以使用 AJAX 请求来验证 token ,但出于安全原因,这些验证应该始终在服务器端完成 - JavaScript 可能总是被用户干扰并被欺骗相信reCAPTCHA 已成功验证。

Google reCAPTCHA docs :

After you get the response token, you need to verify it with reCAPTCHA using the following API to ensure the token is valid.

所以您需要做的是发送您的 reCAPTCHA 密码(在 reCAPTCHA 管理页面中为您生成的第二个 key )和用户响应 token (从 grecaptcha.getResponse() 函数收到的 token ) ) 到 reCAPTCHA API,如 reCAPTCHA docs 中所述.

在 PHP 中,您会这样想:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'secret' => YOUR_RECAPTCHA_SECRET,
'response' => USER_RESPONSE_TOKEN,
]));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);

curl_close($ch);

$response = @json_decode($data);

if ($response && $response->success)
{
// validation succeeded, user input is correct
}
else
{
// response is invalid for some reason
// you can find more in $data->{"error-codes"}
}

关于javascript - Google reCAPTCHA V2 JavaScript 我们检测到您的站点未验证 reCAPTCHA 解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49592772/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com