Php generates 4-digit verification code, and php generates 4-digit verification code _ PHP Tutorial

Source: Internet
Author: User
Php generates the implementation code of the 4-digit verification code, and php generates the 4-digit verification code. Php generates the implementation code of the 4-digit verification code, and php generates the 4-digit verification code. it is very convenient to implement the verification code in php. The key point is to master the usage of phpgd library and session. From the perspective of the implementation code of generating a 4-digit verification code by p php on the Internet, php generates a 4-digit verification code.

It is very convenient to implement the verification code in php. The key point is to master the usage of the php gd library and session.

Looking at the Online php verification code generation example, there is no combination of php gd library and session, and php is used to generate a random number.

PHP verification codes can be divided into many types, includingPhp image verification code, php random verification code,AndPhp Chinese verification codeAnd use different verification codes based on different application scenarios.

Here is a php digital verification code for your reference.

4-digit verification code

/** Filename: authpage. php */session_start (); // srand (double) microtime () * 1000000); $ authnum = $ _ SESSION ['authnum']; // verify whether the user input is consistent with the verification code if (isset ($ _ POST ['authinput']) {if (strcmp ($ _ POST ['authinput'], $ _ SESSION ['authnum']) = 0) echo "verification successful! "; Else echo" verification failed! ";}/// Generate a new four-digit integer verification code // while ($ authnum = rand () % 10000) <1000);?>

Authimg. php

<? Php // Generate the verification code image Header ("Content-type: image/PNG"); srand (double) microtime () * 1000000 ); // play the seeds that generate random numbers to facilitate the use of session_start () for the following random number generation; // Save the random number to the session $ _ SESSION ['authnum'] = ""; $ im = imagecreate (); // specify the image background size $ black = ImageColorAllocate ($ im, 0); // set three colors $ white = ImageColorAllocate ($ im, 255,255,255); $ gray = ImageColorAllocate ($ im, 200,200,200); imagefill ($ im, $ gray); // use the area filling method, set (0, 0) while ($ authnum = rand () % 100000) <10000); // map the four-digit integer verification code to the image $ _ SESSION ['authnum'] = $ authnum; imagestring ($ im, 3, $ authnum, $ black); // use the col color to draw the string s to the x and y coordinates of the image (0, 0 in the upper left corner of the image ). // If the font is 1, 2, 3, 4, or 5, use the built-in font for ($ I = 0; $ I <200; $ I ++) // add interference pixels {$ randcolor = ImageColorallocate ($ im, rand (0,255), rand (0,255), rand (0,255); imagesetpixel ($ im, rand () % 70, rand () % 30, $ randcolor);} ImagePNG ($ im); ImageDestroy ($ im);?>

The above is the implementation code for php to generate a 4-digit verification code. I hope it will help you learn and be able to master php verification code more skillfully.

It is very convenient to implement the verification code in php. The key point is to master the usage of the php gd library and session. Looking at the Internet, p...

Related Article

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.