To tell the truth, mention the verification code I think everyone will be unfamiliar, indeed, the verification code is quite common, now search for PHP verification code class is simply a huge amount of data, then we today to implement a verification code of their own, but it is relatively simple, which is what I said in a simpler way to implement a verification code.
Generally divided into two steps, the first step is to implement a verification code, the second step is to verify through this verification code, we first look at how to implement this verification code, of course, here need to use the knowledge of the GD library, see the following code example:
Here by the way, the basic steps of drawing: first create an image, we use the Imagecreate function, and then use imagecolorallocate to color, and then use a variety of imagexxx to draw the image, and finally use IMAGEXXX to generate a variety of styles of pictures, Finally Imagedestroy to destroy the picture, is basically such a process. Which I feel more worthy of mention is the imagestring parameters, the first picture of painting This does not say, the second parameter represents the font, if the 0,1,2,3,4,5 is a built-in font, the third parameter represents the x-coordinate of the upper-left corner of the painting, The fourth one represents the y-coordinate of the upper-left corner of the painting, and the fifth parameter is the color, which we use to draw in black.
Take a look at what the image we generate looks like:
So how do we use the verification code? Now that the files are written, then we can write a file to import the verification code, and then from the session to get its value, see the following code:
Some javascript is used here, if the reader is not familiar with JavaScript, then big can jump over, the following is the effect of running:
Look, of course, the real project is much more complex, here is a sample program, I hope we progress together.