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.

what error you are getting in apache and php error logs???

---
Manoj

Dear,

If you have root access to the server then first login to the server as root.


Then type :

tail -f /usr/local/apache/log/error_log

for displaying the apache error log.

the syntax : tail -f <apache_config_path>/log/error_log

I'm not a coder so I don't understand your PHP code. However, I admin Apache and know that some scripts which use GD also use true type fonts. If that's the case, then both GD and TTF need to be compiled into Apache. Checking your logs is a good idea, too.

The code above works on my PC. Creates a beautiful white rectangle with a slim red cross inside. Plus the random 6 byte character string. Cool.

Now, HTML code 500. Usually a trivial syntax error:

session_start(;

rather than

session_start(;

throws a 500.

Cool,too

should read:

session_start(;

rather than

session_start();

throws a 500.

Not my day, sorry.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.