<?php
session_start();
if(isset($_SESSION['code'])){
	unset($_SESSION['code']);
}

header("Content-Type:image/png");
$img=@imagecreate(45,20)or die("you can't create image ");
$background_color=imagecolorallocate($img,255,255,255);
$text_color=imagecolorallocate($img,255,0,0);
$line_color=imagecolorallocate($img,200,200,200);
imagefilledrectangle($img,0,0,45,20,$line_color);

for($i=0;$i<4;$i++){
	$number=rand(0,1);
    switch ($number){
        case 0:
    	    $randnumber=rand(50,57);break;//this is a dig number;
        case 2:
            $randnumber=rand(65,90);break;//this is a lower string;
        case 1:
            $randnumber=rand(97,122);break;//this is a upper stirng;
    }
    $asciinumber=sprintf("%c",$randnumber);
    $lastnumber=$lastnumber.$asciinumber;
}

imagestring($img,5,5,2,$lastnumber,$text_color);
imagepng($img);
imagedestroy($img);

$_SESSION['code']=$lastnumber;
?>