?PHP/** * Make Verification code * *. Start the session*2. Set the header. Create a canvas. Create a color. Create a random number and place it on the canvas *6. Add a number of random numbers to the session *7. Adds a disturbance point or interference line *8. Output canvas *9. Destroying Canvas Resources *///1. Start SessionSession_Start();//2. Set the header to specify the MIME output typeHeader(' Content-type:image/png ');//3. Create a canvas$width= 100;$height= 30;$im= Imagecreate ($width,$height);//4. Create Colors$bgcolor= Imagecolorallocate ($im, 255,255,255);$textcolor= Imagecolorallocate ($im, 0,255,255);$randcolor= Imagecolorallocate ($im,Mt_rand(0,200),Mt_rand(0,200),Mt_rand(0,200));//5. Create a random number and place it on the canvas$verify=NULL; for($i= 0;$i<4;$i++){$temp=Mt_rand(0,9);$verify.=$temp; Imagestring ($im, 5,$i*15+15,8,$temp, Imagecolorallocate ($im,Mt_rand(0,200),Mt_rand(0,200),Mt_rand(0,200)));}//6 Put the generated random number in session$_session[' verify '] =$verify;//7. Adding interference points for($i= 0;$i<100;$i++) {Imagesetpixel ($im,Rand(0,$width),Rand(0,$height), Imagecolorallocate ($im,Rand(100,255),Rand(100,255),Rand(100,255)));}//8. Export the imageImagepng ($im);//imagegif ()//9. Destroying an imageImagedestroy ($im);?>
The implementation of PHP verification code