1<?PHP2 //Verification Code Production3 4 Session_Start();5 //generate a Captcha picture6 Header("Content-type:image/png");7 $im= Imagecreate (44,18);//Draw a picture that specifies a wide height8 $back= Imagecolorallocate ($im, 245,245,245);//Define background color9Imagefill ($im, 0, 0,$back);//fill the background color into the picture you just drewTen $vcodes= ""; One Srand((Double)Microtime() *1000000); A $srcstr= "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - //generate 4-bit numbers - for($i= 0;$i<4;$i++) { the $font= Imagecolorallocate ($im,Rand(100,255),Rand(0,100),Rand(100,255));//Generate random Colors - $authnum=$srcstr[Mt_rand(0,35)]; - $vcodes.=$authnum; -Imagestring ($im, 5, 2 +$i* 10, 1,$authnum,$font); + } - $_session[' vcode '] =$vcodes; + A for($i= 0;$i<100;$i++) {//adding interfering pixels at $randcolor= Imagecolorallocate ($im,Rand(0,255),Rand(0,255),Rand(0,255)); -Imagesetpixel ($im,Rand()%70,Rand()%30,$randcolor);//Image Point function - } -Imagepng ($im); -Imagedestroy ($im); -?>
PHP Generate verification Code (II)