I’m creating a simple captcha but cant seem to display random numbers on the captcha my output is always like this:
here is my code:
Blockquote<?php
//start the session
session_start();
header(‘Content-type:image/png’);
//font style for text
//$font = ‘LaBelleAurore.ttf’;
//set the box width and height for the captcha
$image = imagecreatetruecolor(300, 100);
//settomg background color for the box of the captcha white
$background = imagecolorallocate($image, 255, 255, 255);
//some Colors
$white = imagecolorallocate($image, 255, 255, 255);
$yellow = imagecolorallocate($image,255,255,0 );
$black = imagecolorallocate($im, 0,0,0 );
//fill in the captcha box white
imagefilledrectangle($image, 0,0,300,100,$white);
//generate randoms line for the captcha
$line_color = imagecolorallocate($image, 0,0,0);
for ($i=0;$i<=4;$i++){
imageline($image,0,rand(0,100),300,rand(0,100),$line_color);
}
//random dots for more complex captcha
$dots = imagecolorallocate($image, 0,0,255);
for ($i = 0; $i < 2000; $i++){
imagesetpixel($image,rand(0,300),rand(0,100), $dots);
}
//settiing the length of the numbers in the captcha to 4
$length = 4;
//generate random numbers
$text = mt_rand(100,9999);
$_SESSION[“captcha”] = $text;
imagettftext ($image, 18, 0, 35, 30, $black, $text);
imagepng($image);
imagedestroy($image);
?>
any advice ?
thanks in advance