Php? Generate verification code

Source: Internet
Author: User
Php? Which of the following code is used to generate a verification code?


Reply to discussion (solution)

session_start();$dict = str_split('abcdefghijklmnopqrstuv0123456789');shuffle($dict);$_SESSION['word'] = join('', array_slice($dict, -4));$im = imagecreate(100, 30);$bg = imagecolorallocate($im, 255, 255, 255);$char = imagecolorallocate($im, 0, 0, 0);imagestring($im, 5, 10, 10, $_SESSION['word'], $char);imagegif($im);

What kind of verification code do you want?
Let's take a look. it may be helpful to you.
Http://blog.csdn.net/whq19890827/article/details/41778961

Session_start (); $ checkCode = ""; for ($ I = 0; $ I <4; $ I ++) {$ checkCode. = substr ('abcdefghijklmnopqrstuvwxyz0123456789 ', rand (), 1); // $ checkCode. = dechex (rand ();} // Save the random verification code to the session $ _ SESSION ['mycheckcode'] = $ checkCode; // create an image, and draw the random number $ img = imagecreatetruecolor (, 30); // the default background is black // you can specify the background color $ bgcolor = imagecolorallocate ($ img, 0 ); imagefill ($ img, 255,255,255, $ bgcolor); // create a new color $ white = imagecolorallocate ($ img,); $ blue = imagecolorallocate ($ img, 255); $ red = imagecolorallocate ($ img, 255, 0); $ green = imagecolorallocate ($ img, 255, 0, 0 ); // draw interference line segments for ($ I = 0; $ I <20; $ I ++) {// A better way is to use random color imageline ($ img, rand (0,110), rand (0,110), rand (0,255), rand (0,255), imagecolorallocate ($ img, rand (), rand ), rand (0,255);} // draws noise and draws it by yourself. // draw the four random values as imagestring ($ img, rand (), $ checkCode, $ white ); // If you want to use Chinese // array imagefttext (string $ font_file, string $ text [, array $ extrainfo]) // imagettftext ($ img, 15, 10, 20, 25, $ white, "STXINWEI. TTF "," Hello Beijing "); // output header (" content-type: image/png "); imagepng ($ img );

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.