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 );