全部。我一直在尝试集成 Google 的 reCAPTCHA,但在尝试回显 recaptcha_get_html 时似乎失败了。它出现了一个未定义的函数错误。我到处都看过,似乎无法得到直接的答案。我对 PHP 不太了解,并没有完全理解所有内容。有人可以解释一下我如何找到缺少的功能。所以我的问题是,是否需要回显此功能?。这是我的代码:
<form class="" action="verify.php" method="post">
<input type="text" name="email" value=" enter email address" onFocus="if(this.value==' enter email address')this.value='';" style="height:18px; width:218px; color: #cccccc; border: 1 solid #000000; background-color: #5e5e5e; font: xx-small Verdana">
<br><br>
<?php
require_once('recaptchalib.php');
$publickey = "// Public Key";
echo recaptcha_get_html($publickey);
?>
<br>
<input type="submit" id="sendform" name='send' value=" send " style="cursor: hand; height:18px; border: 1 solid #000000; background-color:#5e5e5e; color: #cccccc; font: xx-small Verdana; font-weight:bold">
</form>
提前致谢。
最佳答案
好的,首先,不,你不需要回显那个函数! 正如 J-H 的意思,您可能首先要更新到最新版本的 recaptcha。 这是我在 php 中实现 google recaptcha 的方式
$secret = "Your secret key";
$reCaptcha = new ReCaptcha($secret);
if ($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse (
$_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
}
if(!($response != null && $response->success)) ...
//it was successfully
请注意我没有回显任何东西。另外,公钥应该在 html 中,私钥应该在 PHP 中。公钥不应该在 PHP 中,我不知道那是否是错字,但这也可能是另一个问题。最后,看起来您没有正确使用 html 用于 google recaptcha api,至少是新的。
包括<script src='https://www.google.com/recaptcha/api.js'></script>
在你的标题和 <div style="margin:10px auto 0 auto; width:330px" class="g-recaptcha" data-sitekey="YOUR_SITE_KEY"></div>
您希望重新验证出现的位置。然后你就会有一切工作。干杯
关于php - 为什么需要回显 "recaptcha_get_html"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43614868/