3

我正在尝试在我的服务器上安装此 CAPTCHA 脚本:

http://www.abeautifulsite.net/blog/2011/01/a-simple-php-captcha-script/

我已经上传了文件并尝试运行演示。但是,验证码图像无法正常显示。

当我尝试直接打开验证码图像时,出现此错误

致命错误:在 /home/website/public_html/simple-php-captcha/simple-php-captcha.php:125 中带有消息“未找到字体文件”的未捕获异常“异常”:125 堆栈跟踪:#0 {main} 抛出/home/website/public_html/simple-php-captcha/simple-php-captcha.php 在第 125 行

下面的代码:

Line 125: if( !file_exists($font) ) throw new Exception('Font file not found: ' . $font);

字体文件路径在代码前面设置:

$captcha_config = array(
    'code' => '',
    'min_length' => 5,
    'max_length' => 5,
    'png_backgrounds' => array(dirname(__FILE__) . '/default.png'),
    'fonts' => array(dirname(__FILE__) . '/times_new_yorker.ttf'),
    'characters' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
    'min_font_size' => 24,
    'max_font_size' => 30,
    'color' => '#000',
    'angle_min' => 0,
    'angle_max' => 15,
    'shadow' => true,
    'shadow_color' => '#CCC',
    'shadow_offset_x' => -2,
    'shadow_offset_y' => 2
);

$font = $captcha_config['fonts'][rand(0, count($captcha_config['fonts']) - 1)];

我已经检查过,所有必需的文件都在文件夹中。

有谁知道如何解决这个错误?

4

1 回答 1

0

我刚刚发现简单的 php 验证码对页面缓存不起作用,并且错误地抛出了“找不到字体文件”异常。我确保上面有 CAPTCHA 图像的页面没有被缓存并且问题已经解决。

在我的特定情况下,我有一个/register/包含验证码图像的页面。我正在使用 W3 Total Cache 为我的 WordPress 网站进行页面缓存。

希望这可以帮助。

于 2013-02-21T04:35:02.950 回答