Generate simple verification code _ PHP instance based on php

Source: Internet
Author: User
This article mainly introduces the relevant information about generating simple verification codes based on PHP. if you need more information, you can directly paste the code for your reference. 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.