我需要在我的网站上添加验证码但由于某种原因我收到此错误(来自日志文件):
Warning: imagettfbbox(): Could not find/open font in /home/eric/www/captcha.php on line 24
Warning: imagettftext(): Could not find/open font in /home/eric/www/captcha.php on line 27
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
function generate($width,$height,$characters='6') {
$code = '';
$availableChar = '23456789bcdfghjkmnpqrstvwxyz';
$i = 0;
while ($i < $characters) {
$code .= substr($availableChar, mt_rand(0, strlen($availableChar)-1), 1);
$i++;
}
$image = imagecreate($width, $height);
$text = imagecolorallocate($image, 20, 40, 100);
$things = imagecolorallocate($image, 100, 120, 180);
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $things);
}
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $things);
}
$textbox = imagettfbbox($height, 0, 'monofont.ttf', $code);
imagettftext($image, $height, 0, (($width - $textbox[4])/2), (($height - $textbox[5])/2), $text, 'monofont.ttf' , $code);
imagejpeg($image);
imagedestroy($image);
return $code;
}
header('Content-Type: image/jpeg');
$code = generate(100, 40, 5);
echo $_SESSION['security_code'] = $code;
Run Code Online (Sandbox Code Playgroud)
和我的文件夹中的文件:
-rwxr-xr-x 1 tech4wilco tech4wilco 41036 1999-07-13 23:30 monofont.ttf
-rw-r--r-- 1 tech4wilco tech4wilco 1030 2011-10-17 15:43 captcha.php
Run Code Online (Sandbox Code Playgroud)
我做了一些挖掘,我发现字体需要在那里,因为你可以看到它与PHP文件在同一个文件夹中,我不明白的东西?
| 归档时间: |
|
| 查看次数: |
3422 次 |
| 最近记录: |