【问题标题】:captcha works fine in localhost but not in web server验证码在 localhost 中工作正常,但在 Web 服务器中不能正常工作
【发布时间】:2014-07-12 16:02:13
【问题描述】:

这是我在 captcha.php 中的编码

<?php
/* captcha.php file*/

    session_start();

    header("Expires: Tue, 01 Jan 2013 00:00:00 GMT"); 
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
    header("Cache-Control: no-store, no-cache, must-revalidate"); 
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");

    $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';

    for ($i = 0; $i < 5; $i++) 
    {
        $randomString .= $chars[rand(0, strlen($chars)-1)];
    }

    $_SESSION['captcha'] = strtolower( $randomString );


    $im = @imagecreatefrompng("captcha_bg.png"); 


    imagettftext($im, 30, 0, 10, 38, imagecolorallocate ($im, 0, 0, 0), 'larabiefont.ttf', $randomString);

    header ('Content-type: image/png');
    imagepng($im, NULL, 0);
    imagedestroy($im);

?>

谁能帮我找出错误的地方??? 我已经更改了过期日期,但它仍然不起作用..请帮助我..

谢谢对不起我的英语是passif。

【问题讨论】:

  • 究竟是什么不起作用?验证码是否显示?它会错误地验证吗?你需要更具体。
  • 验证码只显示图像损坏

标签: captcha


【解决方案1】:

如果它在您的本地主机上运行良好,也许您在服务器中缺少一些库/其他配置?

也许你可以输出:

echo phpinfo();

并比较可能的差异......另外,请确保在服务器机器上拥有所有需要的资源(例如 larabiefont.ttf 、 captcha_bg.png )。

【讨论】:

  • 我想是因为php版本。在我的本地主机中,php 版本是 5.5.9,但在 000webhost 它只有 5.2.17。是这个问题吗??
  • 我认为这不会造成任何问题。您可以检查 gd 库是否在服务器上正确设置,以及是否已将 captcha_bg.png 复制到 php 文件的同一文件夹中。并且至少可以读取(检查文件权限)
  • 当我像这样 './larabiefont.ttf' 将 './' 放到 larabiefont.ttf 中时,它终于可以工作了!谢谢各位朋友的回复!!
猜你喜欢
  • 1970-01-01
  • 2015-11-22
  • 1970-01-01
  • 1970-01-01
  • 2017-12-12
  • 1970-01-01
  • 2011-11-11
  • 1970-01-01
  • 2020-07-16
相关资源
最近更新 更多