Html reCAPTCHA 错误:站点密钥的域无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30735694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
reCAPTCHA ERROR: Invalid domain for site key
提问by blestab
I have implemented my reCAPTCHA in line with as is shown in the example.
我已经按照示例中所示实施了我的 reCAPTCHA 。
I have this script in the head
tag:
我在head
标签中有这个脚本:
<script src="https://www.google.com/recaptcha/api.js"></script>
In my form
in HTML I have:
在我form
的 HTML 中,我有:
<div class="g-recaptcha" data-sitekey="my public sitekey here"></div>
But when I load the form
I get this error:
但是当我加载时form
我收到这个错误:
ERROR: Invalid domain for site key
错误:站点密钥的域无效
I have confirmed that this is the correct site key for my domain.
我已确认这是我的域的正确站点密钥。
The code is currently in a subdomain so I thought maybe that was the problem so I also added the subdomain to the Google reCAPTCHA admin but still get the error.
该代码目前在一个子域中,所以我想这可能是问题所在,所以我也将子域添加到了 Google reCAPTCHA 管理员,但仍然出现错误。
The exact same code works 100% in a different domain (with a key specific to that domain).
What could be the problem?
完全相同的代码在不同的域中 100% 工作(具有特定于该域的密钥)。
可能是什么问题呢?
采纳答案by blestab
In case someone has a similar issue. My resolution was to delete the key that was not working and got a new key for my domain. And this now works with all my sub-domains as well without having to explicitly specify them in the recaptcha admin area.
如果有人有类似的问题。我的解决方案是删除无效的密钥并为我的域获取新密钥。这现在也适用于我的所有子域,而无需在 recaptcha 管理区域中明确指定它们。
回答by kqw
First of all, the keys are managed at https://www.google.com/recaptcha/admin#list
首先,密钥在https://www.google.com/recaptcha/admin#list管理
I ran into this error because I'm using the same key on a few different domains and I had forgotten to add one of the domains to the key.
我遇到了这个错误,因为我在几个不同的域上使用了相同的密钥,而我忘记将其中一个域添加到密钥中。
After adding my site it took a minute or two (most likely because of cache) for things to work normally again.
添加我的网站后,它需要一两分钟(很可能是因为缓存)才能再次正常工作。
回答by Alupotha
No need to create a new key just clear site data on browser
无需创建新密钥,只需清除浏览器上的站点数据
If you change your site domain then add that domain to existing key (it's not necessary to a create new one) and save it.
如果您更改站点域,则将该域添加到现有密钥(无需创建新密钥)并保存。
https://www.google.com/recaptcha/admin#list
https://www.google.com/recaptcha/admin#list
but google recapture has some data on browser. Clear them then it will work with your new domain
回答by rawraj
I had the same problems I solved it. I went to https://www.google.com/recaptcha/adminand clicked on the domain and then went to key settings at the bottom.
我遇到了同样的问题,我解决了它。我转到https://www.google.com/recaptcha/admin并单击域,然后转到底部的关键设置。
There I disabled the the option below Domain Name Validation Verify the origin of reCAPTCHA solution
在那里我禁用了下面的选项 域名验证验证 reCAPTCHA 解决方案的来源
clicked on save and captcha started working.
点击保存,验证码开始工作。
I think this has to do with way the server is setup. I am on a shared hosting and just was transferred without notice from Liquidweb to Deluxehosting(as the former sold their share hosting to the latter) and have been having such problems with many issues. Here is think google is checking the server but it is identifying as shared server name and not my domain. When i uncheck the "verify origin" it starts working. Hope this helps solve the problem for the time being.
我认为这与服务器的设置方式有关。我在共享主机上,只是在没有通知的情况下从 Liquidweb 转移到 Deluxehosting(因为前者将他们的共享主机卖给了后者),并且遇到了很多问题。这是认为谷歌正在检查服务器,但它识别为共享服务器名称而不是我的域。当我取消选中“验证来源”时,它开始工作。希望这有助于暂时解决问题。
回答by hugronaphor
回答by sanmai
You may have inadvertently used a private key for a public key.
您可能无意中将私钥用于公钥。
回答by ttemple
I was using localhost during unit testing when my recaptcha key was registered to 127.0.0.1. So I changed my browser to point to 127.0.0.1 and it started working. Although I was able to add "localhost" to the list of domains in my ReCaptcha Key Settings, I am still unable to unit test using localhost. I have to use the loopback IP address 127.0.0.1.
当我的 recaptcha 密钥注册到 127.0.0.1 时,我在单元测试期间使用 localhost。因此,我将浏览器更改为指向 127.0.0.1 并开始工作。尽管我能够将“localhost”添加到我的 ReCaptcha 密钥设置中的域列表中,但我仍然无法使用 localhost 进行单元测试。我必须使用环回 IP 地址 127.0.0.1。
回答by DharmendraSankhla
There is another point must be noted before regenerating keys that resolve 90% issue.
在重新生成解决 90% 问题的密钥之前,必须注意另一点。
for example your xampp directory is C:\xampp
例如你的 xampp 目录是 C:\xampp
and htdocs folder is C:\xampp\htdocs
htdocs 文件夹是 C:\xampp\htdocs
we want to open page called: example-cap.html and page is showing error "invalid domain for site key"
我们要打开名为:example-cap.html 的页面,页面显示错误“站点密钥的域无效”
USE YOUR LOCALHOST ADDRESS in browser address like:
在浏览器地址中使用您的本地主机地址,例如:
localhost/example-cap.html
本地主机/示例cap.html
this will resolve your issue
这将解决您的问题
DONOT USE ADDRESS c:\xampp\htdocs\example-cap.html this will generate error
不要使用地址 c:\xampp\htdocs\example-cap.html 这会产生错误
回答by kylestephens
I ran into this issue also and my solution was to verify I was integrating the appropriate client code for the version I had selected.
我也遇到了这个问题,我的解决方案是验证我是否为我选择的版本集成了适当的客户端代码。
In my case, I had selected reCAPTCHA v3 but was taking client integration code for v2.
就我而言,我选择了 reCAPTCHA v3,但正在使用 v2 的客户端集成代码。
V3 looks like this:
V3 看起来像这样:
<script src="https://www.google.com/recaptcha/api.js?render=reCAPTCHA_site_key"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'}).then(function(token) {
...
});
});
</script>
V2 code looks like this:
V2 代码如下所示:
<html>
<head>
<title>reCAPTCHA demo: Simple page</title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<form action="?" method="POST">
<div class="g-recaptcha" data-sitekey="your_site_key"></div>
<br/>
<input type="submit" value="Submit">
</form>
</body>
</html>
As for which version you have, this will be what you decided at the start of your reCAPTCHA account setup.
回答by Dapo Momodu
Make sure you fill in your domain name and it must not end with a path.
确保填写您的域名,并且不能以路径结尾。
example
例子
http://yourdomain.com(good)
http://yourdomain.com/folder(error)