1<?PHP2 3 $type=1;4 $len=4;5 Header("Content-type:image/png");6 //test function7 Newcode ();8 9 functionNewcode ($type=1,$len=4){Ten One //Verification Code Content A $str= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - if($type==1){ the $m=9; -}ElseIf($type==2){ - $m=35; -}Else{ + $m=61; - } + $code=""; A for($i= 0;$i<$len;$i++){ at $code.=$str[Rand(0,$m)];//Random Get Verification code - } - //Create a canvas - $im=imagecreatetruecolor (50*$len, 50); - //creating brushes and backgrounds - $BG=imagecolorallocate ($im, 230,230,230); in $HB=imagecolorallocate ($im,Rand(0,255),Rand(0,255),Rand(0,255)); - //Background Fill toImagefill ($im, 0, 0,$BG); + //add a random color to the noise point - for($i= 0;$i<50*$len;$i++){ the $HB=imagecolorallocate ($im,Rand(0,255),Rand(0,255),Rand(0,255)); *Imagesetpixel ($im,Rand(0,50*$len),Rand(0,50),$HB); $ }Panax Notoginseng //adding random interference lines - for($i= 0;$i<$len;$i++){ the $HB=imagecolorallocate ($im,Rand(0,255),Rand(0,255),Rand(0,255)); +Imageline ($im,Rand(0,50*$len),Rand(0,50),Rand(0,50*$len),Rand(0,50),$HB); A } the //Add Verification Code + for($i= 0;$i<$len;$i++){ - $HB=imagecolorallocate ($im,Rand(0,255),Rand(0,255),Rand(0,255)); $Imagettftext ($im, 40,Rand( -30,30), 20+40*$i, 44,$HB, "Msyh.ttf",$code[$i]); $ } - //Output Verification Code -Imagepng ($im); the //Freeing Resources -Imagedestroy ($im);Wuyi the - } Wu - About?>
Random Verification Code