错误:站点密钥的域无效 [英] ERROR:Invalid domain for site key
问题描述
关于 reCaptcha,我需要您的帮助.Recaptcha 在本地主机上运行良好,但是当我尝试从另一台机器访问它时,它给了我这个错误
I need your help regarding reCaptcha. Recaptcha works well on localhost, but when I try accessing it from a different machine it gives me this error
错误:站点密钥的域无效
ERROR:Invalid domain for site key
但我使用的是从 reCaptcha 网站
推荐答案
如果你想在本地主机上运行 reCaptcha,你应该使用这里描述的安全令牌:google 安全令牌文档这解决了我自己的本地主机问题.以前我收到一条错误消息站点密钥的域无效".这可能是因为没有人说本地主机必须命名为本地主机"或具有用于本地主机的标准 IP.无论如何,使用安全令牌完全解决了这个问题.
If you want to run reCaptcha on localhost you should use secure token like described here: google secure token documentation this solved my own localhost problem. Previously I had an error message "Invalid domain for site key". This may be because nobody says that a localhost has to be named 'localhost' or have the standard IP used for localhosts. Anyways using the secure token solved this completely.
为了生成安全令牌,我使用了 slushie 的 php 实现
For secure token generation I'm using slushie's php implementation
PHP 部分:
<?PHP
use ReCaptchaSecureToken\ReCaptchaToken as ReCaptchaToken;
require_once("libs/ReCaptchaToken.php");
//Generate recaptcha token
$config = [ 'site_key' => 'place-your-site-key-here',
'site_secret' => 'place-your-secret-key-here'
];
$recaptcha_token = new ReCaptchaToken($config);
$recaptcha_session_id = uniqid('recaptcha');
$recaptcha_secure_token = $recaptcha_token->secureToken($recaptcha_session_id);
?>
HTML:
<html>
<head>
...
<script src='//www.google.com/recaptcha/api.js'></script>
</head>
<body>
<form>
...
<div class="g-recaptcha" data-sitekey="place-your-site-key-here" data-stoken="<?PHP echo $recaptcha_secure_token; ?>"></div>
</form>
</body>
</html>
这篇关于错误:站点密钥的域无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!