在php脚本上生成captcha图像时出错


Error generating captcha image on php script

我正试图制定一个算法来进行captcha验证,但脚本返回错误"the image"http://localhost/cptest/captchateste.php"无法显示,因为它包含错误。"

这两个循环中的一个可能有错误的部分,但我对php没有太多经验,也无法理解。这里可能有什么错误?感谢

<?php
session_start();
$width  = 120;
$height =  40;
$length =   5;
$baseList = '0123456789abcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$code    = "";
$counter = 0;
$image = @imagecreate($width, $height) or die('Cannot initialize GD!');
for( $i=0; $i<10; $i++ ) {
   imageline($image,mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height),imagecolorallocate($image, mt_rand(150,255),mt_rand(150,255), mt_rand(150,255)));
}
for( $i=0, $x=0; $i<$length; $i++ ) {
   $actChar = substr($baseList, rand(0, strlen($baseList)-1), 1);
   $x += 10 + mt_rand(0,10);
   imagechar($image, mt_rand(3,5), $x, mt_rand(5,20), $actChar,imagecolorallocate($image, mt_rand(0,155), mt_rand(0,155),mt_rand(0,155)));
   $code .= strtolower($actChar);
}
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['securityCode'] = $code;
?>

这段代码在我的系统中运行良好我认为显示图像没有任何问题最好再次运行代码,然后返回您得到的错误如果您是php的新手,请使用控制台窗口调试脚本错误