Php verification code example code _ PHP Tutorial

Source: Internet
Author: User
Php verification code. If you want to use the php drawing function, you must first enable the function of this module. Just remove the comments before php_gd2.dll in php. ini. Next, start drawing: Copy the code as follows. if you want to use the php drawing function, first enable the function of this module. Just remove the comments before php_gd2.dll in php. ini.
Draw a picture below:

The code is as follows:


  Session_start ();
// Generate a verification code Image
Header ("Content-type: image/PNG ");
$ Im = imagecreate (); // draw an image with the specified width and height
$ Back = ImageColorAllocate ($ im, 245,245,245); // defines the background color.
Imagefill ($ im, $ back); // fill the background color in the image you just Drew
$ Vcodes = "";
Srand (double) microtime () * 1000000 );
// Generate four digits
For ($ I = 0; $ I <4; $ I ++ ){
$ Font = ImageColorAllocate ($ im, rand (100,255), rand (0,100), rand (100,255); // Generate a random color
$ Authnum = rand (1, 9 );
$ Vcodes. = $ authnum;
Imagestring ($ im, 5, 2 + $ I * 10, 1, $ authnum, $ font );
}
$ _ SESSION ['vcode'] = $ vcodes;
For ($ I = 0; $ I <100; $ I ++) // add interference pixels
{
$ Randcolor = ImageColorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
Imagesetpixel ($ im, rand () % 70, rand () % 30, $ randcolor); // draws the pixel point function
}
ImagePNG ($ im );
ImageDestroy ($ im );
?>


This is basically how it works. In fact, if you add a watermark to an image, you can simply write it in the image.
Used directly
Enter the name of the PHP file.

Bytes. Just remove the comments before php_gd2.dll in php. ini. The code is as follows...

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.