Generate random number verification codes for pure numbers, alphanumeric, images, and pure Chinese characters via PHP

Source: Internet
Author: User

Now start to generate a variety of PHP verification code journey, novice to drive, please swipe!

First of all, let's start mister into a background image with a CAPTCHA

Note: There is no imagejpg () function, only the imagepng () function

Imagecreatetruecolor () function meaning

Effect

Considering the background image of our general verification code is white, we will now change the background image

Effect

Correlation function meaning

Note: before outputting a picture, we have to generate the header ("Content-type:image/png"), which tells the server to output a picture

First, generate a pure digital verification code

1. The code part that produces the number

Effect

Related functions

Sets the color of the number to random

Effect

Note: control font size and distribution, avoid font overlap or font display (i.e. control the definition of x and y axes)

2, increase the interference element (point Element)

Code section

Effect

Related functions

3. Add interference element (line Element)

Effect

Related functions

Note: interference information must control the color, avoid the color bar number to cover the

Second, the generation of alphanumeric verification code

1, first of all the relevant settings of the pure number to comment out, to avoid interference

Code section

Effect

Tip: We can filter the displayed content, such as the number 0 and the letter O is similar, can be deleted (the letter L and the number 1, the letter Z and the number 2), so that users have a better experience

Note: Sometimes we filter to filter an empty content, the verification code will appear only three or three characters or less, then we can avoid

Third, through seseion storage user authentication information

1, first of all, we know that when we want to use the session to store information, we will be in the PHP file at the top of the session to open

Secondly, we need to store with the session, then:

2, verification code submitted through the form, check

Form Code Section

Effect

Code that validates the background after the user submits the verification code (written at the top of the form.php)

Test

Setting case-insensitive validation

Four, dynamic calibration design

1. Code part

Effect

Five, image verification Code

1. Code part

2. Front-End part

Effect

Six, Chinese character Verification code

1, the Chinese character verification code and the alphanumeric verification code is similar, the slight modification is good, the code part

Effect

Front-end Section

Effect

2, the need for more information on Chinese characters

The front end is the same

Effect

Related functions

Note: Select the font style to support Chinese, such as simplified, bold and so on

The above is the relevant verification code implementation content, you learned it!!! Come on

                                              

END

Generate random number verification codes for pure numbers, alphanumeric, images, and pure Chinese characters via PHP

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: info-contact@alibabacloud.com 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.