Verification code creation (Network tree comment)

Source: Internet
Author: User
1. use the for loop to generate random numbers. Use a random function to generate a random number within the specified range. For example, rand () generates numbers between 1 and 15. Use a hexadecimal function to create numbers and letters. Dechex (rand (1, 15 )). Use the. = operation to save several numbers. Place the generated random number to $ _ SESSION [variable]. "> <LINKhref

1. Generate a random number
Use the for loop to generate several random numbers.
Use a random function to generate a random number within the specified range. For example, rand () generates numbers between 1 and 15.
Use a hexadecimal function to create numbers and letters. Dechex (rand (1, 15 )).
Use the. = operation to save several numbers.

Place the generated random number to $ _ SESSION [variable]. .

2. create an image
Use the image creation function to determine the size of the created image.
For example, $ im = imagecreatetruecolor (, 30); the coordinates, 30 are the origin point in the upper left corner of the page, and $ im is the image variable.

3. set the color.
Use the function to create a background color. For example, $ bg = imagecolorallocate ($ im, 0); where 0, 0 is the primary color number, $ im is the image created above
Use the function to create a font color. For example, $ te = imagecolorallocate ($ im, 255,255,255 );

4. write the characters in the upper left corner of the image.
Use the imagestring () function to write the character in the image. For example, imagestring ($ im, 5, 0, 0, $ rand, $ te); $ im is the image created above, 5 is the display mode, 0, 0

Is the coordinate, $ te is the font color

5. output image
Use the function header ("Content-type: image/jpeg"); imagejpeg ($ im); to output the image.

---------------------------------- I am a gorgeous split line ---------------------------
1. enable the session function. for example, session_start ();

2. write a form

3. compare the verification code data submitted by the form with the above $ _ SESSION [variable]
Equal. the verification is correct.
Otherwise, an error occurs.
 

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.