Php 未加载我的验证码图像。存在内部服务器错误505

Php 未加载我的验证码图像。存在内部服务器错误505,php,captcha,Php,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('

我有一个用于验证码的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文件所在的同一文件夹中。请帮我做这个。未加载此验证码图像。

首先删除ob\u start命令。至少对我来说,这没有多大意义。 然后取消对标题的注释。。行,以便在浏览器中看到错误消息。 我必须执行以下操作才能启动并运行代码:

我删除了mimetypes行,这是PHP吗?如果是,则缺少分号 脚本没有找到字体-我必须使用绝对路径并设置正确的权限
完成调试并在浏览器窗口中看到花式字符后,添加标题。。再次行。

日志文件中的错误是什么,是否安装了libjpeg?网页上没有任何错误。只是一个小的破碎图像图标。控制台中的错误是:加载资源失败:服务器响应状态为500 Internal serverError@Miguelo请帮帮我。我需要尽快完成这个。感谢您的关注。字体文件为'arial.ttf',它位于img.php文件所在的同一文件夹中。所以我认为$font='arial.ttf'应该可以工作。但是我设置了:mimetypes.add_type'application/x-opentype','ttf',True;我在控制台中得到一个错误,即:资源被解释为字体,但使用MIME类型Font/woff传输:.1。mimetypes.add行似乎是Python 2。至于控制台,你说的是chrome或类似的开发工具,这里根本不涉及。是否删除了第一行并取消了mime头行的注释以进行调试?您现在应该可以看到错误消息了。如果没有,则添加错误报告全部;作为第一行。最终,浏览器在arial.ttfI上没有读访问权限,按u所说的方式检查,但还是一样的。未生成图像。