PHP version of the verification code program _ PHP Tutorial

Source: Internet
Author: User
PHP verification code program .? Php generates the verification code Image Header (Content-type: imagePNG); srand (double) microtime () * 1000000); play the next seed to generate random numbers to facilitate the use of the following random number generation // Generate a verification code Image
Header ("Content-type: image/PNG ");
Srand (double) microtime () * 1000000); // play the next seed that generates random numbers to facilitate the use of the following random number generation

Session_start (); // Save the random number to the session.
$ _ SESSION ['authnum'] = "";
$ Im = imagecreate (); // specify the image background size.

$ Black = ImageColorAllocate ($ im, 0, 0); // you can specify 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 used.

For ($ I = 0; $ I <200; $ I) // add interference pixels
{
$ Randcolor = ImageColorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
Imagesetpixel ($ im, rand () p, rand () 0, $ randcolor );
}


ImagePNG ($ im );
ImageDestroy ($ im );
?>

Http://www.bkjia.com/PHPjc/631989.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631989.htmlTechArticle? Php // Generate the verification code image Header (Content-type: image/PNG); srand (double) microtime () * 1000000); // play the next seed that generates random numbers, to facilitate the use of the following random number generation...

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.