Hi guys,
A little trouble finishing of a log-on script with captcha-check. Hope you can spot it.
I have just started messing around with the GD graphics libary for PHP to complete a log-on script and I’m trying to create a captcha process with it. I have installed the GD library for PHP, but still the below code results in nothing but a blank, white browserpage with a small “broken file” icon in the top-left corner of the white browser area. What should I be checking for first?
The code:
$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;
// CAPTCHA GENERATOR END
$token = md5(uniqid(rand(), TRUE));
$_SESSION['token'] = $token;
echo sprintf("<form action='/musicartcenter.php' method='post'>
<fieldset>
<legend>Please enter the code below as you see it:</legend>
<p><label>Captcha</label><img src='/musicartcenter.php' />
<input type='text' name=secCode size=10 />
<input type='hidden' name='formtoken' value='%s'>
<span><input name='submitBtn' type='submit' value='process_captcha' /></span>
</fieldset>
</form>", $token);
die('</div><!-- applicationarea end -->');
}
}
}
The PHP config:
[ATTACH]4621[/ATTACH]
Thx for the glancing over.
GD.png