php - 为什么需要回显 "recaptcha_get_html"?

标签 php html css recaptcha

全部。我一直在尝试集成 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">
      &nbsp; <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/

相关文章:

php - MYSQL 中的 UPDATE SET 合并

html - 如何编辑水平下拉菜单

jquery - 单击时停止 css 动画闪烁图像

javascript - 将表单输入值附加到操作 url 作为路径

html - 为什么我的页面元素在页面加载时都是从左上角进来的?

html - CSS/HTML : How to make dropdown menu work

html - 如何在图像下放置 figcaption

php - mysql 数据库中的 php 中不显示中文字符

php - 社交网络墙发布逻辑不起作用

PHP 在生成文档时在服务器上创建文档副本