我的captcha图像没有加载.存在内部服务器错误505



我有一个用于captcha的php文件。但图片并没有出现在网页上。我不知道出了什么问题。请帮帮我。这是我的密码。

<?php
ob_start();
session_start();
// Set the content-type
header('Content-Type: image/jpeg');
mimetypes.add_type('application/font-ttf', '.ttf', True)
// Create the image
$im = imagecreatefromjpeg('bg.jpg');
// Create some colors
$R = rand(0,100);
$G = rand(0,100);
$B = rand(0,100);
$cc = imagecolorallocate($im, $R, $G, $B);

// The text to draw
$text = rand(100,10000);
$_SESSION['text'] = $text;
// Replace path by your own font path
$font = 'arial.ttf';

// Add the text
imagettftext($im, rand(40,45), rand(0,1), rand(10,70), rand(38,50), $cc, $font, $text);
$NumberOfLines=15;
imagecolorallocate($im, 15, 142, 210);
$cc=0;
while($cc < $NumberOfLines){
// set random color:::
//assign random rgb values
$c1 = mt_rand(50,200); //r(ed)
$c2 = mt_rand(50,200); //g(reen)
$c3 = mt_rand(50,200); //b(lue)
//test if we have used up palette
if(imagecolorstotal($im)>=255) {
    //palette used up; pick closest assigned color
    $color = imagecolorclosest($im, $c1, $c2, $c3);
} else {
    //palette NOT used up; assign new color
    $color = imagecolorallocate($im, $c1, $c2, $c3);
}
// done...
$startH =rand(3,200);
$startTOP = rand(0,8);
$stopH=rand(3,200);
$stopTOP =50;
imageline($im, $startH, $startTOP, $stopH, $stopTOP, $color);
$cc++;
}
// Using imagepng() results in clearer text compared with imagejpeg()
imagejpeg($im);
imagedestroy($im);
?>

这个脚本文件的名称是img.php,它被设置为img的src标签式img src='img.php'这里arial.ttf文件位于这个php文件所在的同一文件夹中。请帮我一下。此captcha图像未加载。

首先删除ob_start()命令。这没有多大意义(至少对我来说)。然后取消对标题(..)行的注释,以便在浏览器中看到错误消息。我必须做以下事情来启动并运行代码:

  • 我删除了mimetypes行(这是PHP吗?如果是,则缺少分号)
  • 脚本找不到字体-我必须使用绝对路径并设置权限

调试完成后,在浏览器窗口中看到漂亮的字符,请再次添加头(..)行。

最新更新