Sinsing and you to implement the verification code in PHP in a simpler way

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.