Php program how to generate a verification code Image
Source: Internet
Author: User
? Php // native verification code image Header ("Content-type: image/PNG"); srand (double) microtime () * 1000000 ); // play the seeds of the next natural random number to facilitate the application of session_start (); // Save the random number to the session $ _ SESSION [' // Native verification code Image
Header ('content-type: image/PNG ');
Srand (double) microtime () * 1000000); // play the seed of the next natural random number to facilitate the natural application of the following random number
Session_start (); // 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)
While ($ authnum = rand () 0000) <10000 );
// Print the four-digit integer verification code into the image
$ _ SESSION ['authnum'] = $ authnum;
Imagestring ($ im, 5, 10, 3, $ authnum, $ black );
// Use the col color to draw the string s to the x and y coordinates of the image (0 and 0 in the upper left corner of the image ).
// If the font is 1, 2, 3, 4, or 5, the built-in font is applied.
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