Xin Xing and you use a simpler method to implement the verification code in PHP. to tell the truth, I don't think everyone is familiar with the verification code. Indeed, the verification code is quite common, search for the PHP verification code class is a massive amount of data, so today we will implement our own verification code, but it is relatively simple, this is what I said to implement a verification code in a simpler way.
In general, there are two steps. The first step is to implement a verification code. The second step is to verify the verification code. let's take a look at how to implement the verification code first, of course, the gd Library is required here. please refer to the following code example:
Here, by the way, the basic steps for drawing are as follows: first create an image, we use the imagecreate function, then use imagecolorallocate to color the image, and then use various imagexxx to draw the image, finally, imagexxx is used to generate images of various styles, and imagedestroy is used to destroy images. this process is generally the case. Among them, I think it is worth mentioning the imagestring parameter. The first parameter indicates the image to be painted. The second parameter indicates the font. if it is 0, 1, 2, 3, 4, 5 indicates the built-in font, the third parameter indicates the x coordinate in the upper left corner of the painting, the fourth parameter indicates the y coordinate in the upper left corner of the painting, and the fifth parameter indicates the color, here we use black for plotting.
Let's take a look at what the generated image looks like:
How can we use the verification code? Since all the files have been written, we can write another file to import the verification code, and then get its value from the session. See the following code: