This article mainly and everyone to share the code of PHP Implementation Verification code, in addition to JS can implement the verification code function, PHP can also, hope to help everyone.
<?phpheader ("Content-type:image/png"); This is a picture format $imgwidth = +; width $imgheight = +; Height $font = ' nflbronc. TTF '; Font $img = Imagecreatetruecolor ($imgwidth, $imgheight); Create a true color image//Generate color function color () {global $img;//DECLARE global variable return imagecolorallocate ($img, Rand (0,200), Rand (0,200), Rand (0,200)); Output a color} $white = Imagecolorallocate ($img, 255, 255, 255); Imagefill ($img, 0,0, $white); Fill Color//Generate random verification code $code = '; for ($i =0; $i <4; $i + +) {if (rand (0,1000)%2==0) {$code =chr (rand (97,122));} else{$code =rand (0,9);} $x = $i *20+10; $y = 30; Imageline ($img, Rand (0,20), Rand (10,20), Rand (20,120), Rand (20,30), Color ()), Imagettftext ($img, 20,0, $x, $y, Color (), $ Font, $code);} Add noise interference for ($i =0; $i <100; $i + +) { imagesetpixel ($img, rand (0), rand (0, +), color ()); Imagesetpixel ($img, rand (0, +), rand (0, +), color ());} Output Verification Code imagepng ($IMG);//Close Imagedestroy ($img);? >