I am getting the 500 Server Error message when I try to run my captcha script. The script is as follows:
<?php
//Start the session so we can store what the security code actually is
session_start();
//Send a generated image to the browser
create_image();
exit();
function create_image()
{
/*//Let's generate a totally random string using md5
$md5_hash = md5(rand(0,999));
//We don't need a 32 character long string so we trim it down to 5
$security_code = substr($md5_hash, 15, 5); */
$codelength = 6;
while($newcode_length < $codelength) {
$x=1;
$y=3;
$part = rand($x,$y);
if($part==1){$a=48;$b=57;} // Numbers
if($part==2){$a=65;$b=90;} // UpperCase
if($part==3){$a=97;$b=122;} // LowerCase
$code_part=chr(rand($a,$b));
$newcode_length = $newcode_length + 1;
$newcode = $newcode.$code_part;
}
$security_code = $newcode;
//Set the session to store the security code
$_SESSION["security_code"] = $security_code;
//Set the image width and height
$width = 100;
$height = 22;
//Create the image resource
$image = ImageCreate($width, $height);
//We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$grey = ImageColorAllocate($image, 204, 204, 204);
$red = ImageColorAllocate($image, 255, 0, 0);
//Make the background black
ImageFill($image, 0, 0, $white);
//Add randomly generated string in white to the image
ImageString($image, 5, 26, 3, $security_code, $black);
//Throw in some lines to make it a little bit harder for any bots to break
ImageRectangle($image,0,0,$width-1,$height-1,$grey);
imageline($image, 0, $height/2, $width, $height/2, $red);
imageline($image, $width/2, 0, $width/2, $height, $red);
//imageline($image, 0, 0, $width, $height, $grey);
//imageline($image, $width, 0, 0, $height, $red);
//Tell the browser what kind of file is come in
header("Content-Type: image/jpeg");
//Output the newly created image in jpeg format
ImageJpeg($image);
//Free up resources
ImageDestroy($image);
}
?>
I am using a Mandriva "Mandrake" Linux server with Apache2 and PHP5 both installed. I have GD installed as well so I have no idea what the problem could be.