Generate simple verification codes based on PHP, and generate simple verification codes based on PHP.

Source: Internet
Author: User

Generate simple verification codes based on PHP, and generate simple verification codes based on PHP.

If you don't talk much about it, paste the Code directly. The specific code is as follows:

For ($ I = 0; $ I <5; $ I ++) {$ rand. = dechex (rand (); // a random number is generated in hexadecimal notation 1-F.} $ im = imagecreatetruecolor (); // The verification code size (canvas) $ bg = imagecolorallocate ($ im, 100, 0); // background color for ($ I <0; $ I <; $ I ++) {$ color_dian = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255); imagesetpixel ($ im, rand () % 100, rand () % 30, $ color_dian); // draw a vertex on the canvas} $ color_font = imagecolorallocate ($ im, rand (88,255), rand (88,255), rand (100,255 )); // set the color of the color text $ color_line = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 )); // set the color line imageline ($ im, rand (80,100), rand (), rand (), $ color_line ); // The line starts from the second parameter. The X axis and Y axis of the line header, the end X axis, the Y axis, the assigned color imagestring ($ im, 5, rand (), rand ), $ rand, $ color_font ); // write the generated code on the canvas. The font attributes start from the second parameter, the position X axis, Y axis, Random verification code, and color displayed on the canvas. // imagettftext ($ im, 12, 0, 12, 20, $ color_font, 'haha. ttf', ""); write the header ("Content-type: image/jpeg") on the canvas "); // declare what you want to output imagejpeg ($ im); // output the image to the browser in jpeg format

The above code is a simple verification code generated based on PHP introduced by the small Editor. The code is accompanied by a comment. If you have any questions during the reference process, please leave a message to me. The small editor will reply to you in time.

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.