The example of this article for everyone to share the code of PHP generated verification codes, for your reference, the specific content as follows
<?php$im=imagecreate (200,100);//Generate Canvas Imagecolorallocate ($im, 0,0,0);//background-color $white=imagecolorallocate ($im, Rand ( 0,255), Rand (0,255), Rand (0,255));//Generate Random color for ($i =0; $i <9; $i + +) {Imageline ($im, Rand (0,200), Rand (0,100), Rand ( 0,200), Rand (0,100), $white);//Generate Interference line elements}for ($i =0; $i <150; $i + +) {Imagesetpixel ($im, Rand (0,200), Rand (0,100), $ white);//Generate a disturbance point element}for ($i =0, $str = "; $i <4; $i + +)//To get four characters {switch (rand (1,3)) {case ' 1 ': $ch =rand (0,9); break; Case ' 2 ': $ch =sprintf ('%c ', rand (97,122)); break; Case ' 3 ': $ch =sprintf ('%c ', rand (65,90)); Break } $str. = $ch;} Imagettftext ($im, 32,rand (0,15), 55,70, $white, ' C.TTC ', $str);//output string header on canvas ("Content-type:image/jpeg"); Imagejpeg ($im); Imagedestroy ($im);? >
The above is the whole content of this article, I hope that you learn PHP programming help.
The above describes the PHP generated cool four character verification code, including the verification Code, PHP content, I hope to be interested in PHP tutorial friends helpful.