【问题标题】:captcha image is not visible in php验证码图像在 php 中不可见
【发布时间】:2014-04-28 15:45:51
【问题描述】:

我已经在 centos 服务器中预装了 GD 库和 Freetype 库。 我看不到验证码图片。

错误:

Call to undefined function imagettfbbox() in /path/public_html/captcha/securimage.php

可能是什么原因?

谢谢。

【问题讨论】:

  • 你可能没有正确安装。
  • 如果您查看phpinfo(); 的输出,您是否看到了两个扩展?
  • 我可以看到 GD 扩展。我看不到 Freetype。但是,在命令行中它说它已经安装了。
  • 命令行 != 网络服务器。它们都可以有不同的 php.ini 文件。
  • 我使用 SSH 连接

标签: php gd captcha


【解决方案1】:

尝试使用 reCAPTCHA在某些托管服务器中,基于 GD 的验证码不起作用。我经历过。 reCAPTCHA 可以在没有 GD 库的情况下使用。 它从外部服务加载验证码图像并使用公钥加密进行验证。 所以 NO 内部生成验证码图像。 非常容易使用。

E.G:

前端:

<html>
    <body> <!-- the body tag is required or the CAPTCHA may not show on some browsers -->
      <!-- your HTML content -->

      <form method="post" action="verify.php">
        <?php
          require_once('recaptchalib.php');
          $publickey = "your_public_key"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        ?>
        <input type="submit" />
      </form>

      <!-- more of your HTML content -->
    </body>
  </html>

后端验证:

<?php
  require_once('recaptchalib.php');
  $privatekey = "your_private_key";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }
  ?>

欲了解更多信息,请访问:https://developers.google.com/recaptcha/docs/php

【讨论】:

    猜你喜欢
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 2015-07-16
    • 1970-01-01
    • 2012-11-06
    • 2023-03-24
    相关资源
    最近更新 更多