简体   繁体   English

如何在基于HTML的网站中验证recapcha v2

[英]How do i validate recapcha v2 in html based website

I have attached the code which i am using and while loading the page it is giving me error saying 我已附上我正在使用的代码,并且在加载页面时出现错误提示

Cannot contact reCAPTCHA. 无法联系reCAPTCHA。 Check your connection and try again. 检查您的连接,然后重试。

Please be remember I'm not going to use any server side code. 请记住,我不会使用任何服务器端代码。 My website is having simple html. 我的网站上有简单的HTML。

<html>
<head>
<title>reCAPTCHA demo: Explicit render after an onload callback</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<div class="g-recaptcha" data-sitekey="my_site_key"></div>
</body>
</html>

In short you can't. 简而言之,你不能。 You have to send your site key, secret key and response to the Google API to verify it. 您必须将您的站点密钥,秘密密钥和响应发送给Google API进行验证。

However there is a solution to check if the captcha is filled. 但是,有一种解决方案可以检查验证码是否已满。 When a user solves the captcha there is a element which gets filled named g-recaptcha-response . 当用户解决验证码时,会填充一个名为g-recaptcha-response的元素。

With some javascript you can check if the user has solved the captcha. 使用某些JavaScript,您可以检查用户是否已解决了验证码。

var response = grecaptcha.getResponse();

if(response.length == 0)
    //reCaptcha not verified

else
    //reCaptch verified

However this solution is not a save one. 但是,此解决方案不是省钱的。 If someone just changes the dom so it looks like the element g-recaptcha-response is filled it will pass your validation. 如果有人只是更改了dom,以便看起来g-recaptcha-response元素已填充,它将通过您的验证。 To be absolute sure the captcha is solved you have to send a API request to Google. 要绝对确定验证码已解决,您必须向Google发送API请求。

EDIT: Also this question has been asked before (multiple times). 编辑:同样,这个问题已经被问过(多次)。
How can I validate google reCAPTCHA v2 using javascript/jQuery? 如何使用javascript / jQuery验证Google reCAPTCHA v2?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM