- Session_start ();
- Function random ($ len)
- {
- $ SrCStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
- $ Strs = "";
- For ($ I = 0; $ I <$ len; $ I ++)
- {
- $ Strs. = $ srCStr [mt_rand (0, 35)];
- }
- Return $ strs;
- }
- $ Str = random (4); // randomly generated string
- $ Width = 50; // the image width of the verification code
- $ Height = 25; // height of the verification code Image
- @ Header ("Content-Type: image/png ");
- $ _ SESSION ["code"] = $ str;
- $ Im = imagecreate ($ width, $ height );
- // Background color
- $ Back = imagecolorallocate ($ im, 0xFF, 0xFF, 0xFF );
- // Blur the vertex color
- $ Pix = imagecolorallocate ($ im, 187,230,247 );
- // Font color
- $ Font = imagecolorallocate ($ im, 41,163,238 );
- // Plot the vertices of fuzzy match.
- For ($ I = 0; I I <1000; $ I ++)
- {
- Imagesetpixel ($ im, mt_rand (0, $ width), mt_rand (0, $ height), $ pix );
- }
- Imagestring ($ im, 5, 7, 5, $ str, $ font );
- Imagerectangle ($ im, 0, 0, $ width-1, $ height-1, $ font );
- Imagepng ($ im );
- Imagedestroy ($ im );
- $ _ SESSION ["code"] = $ str;
- ?>
Summary: from PHP 4.2.0, the random number generator is no longer needed to be planted using the srand () or mt_srand () function, which is now automatically completed. Articles you may be interested in: php generates N non-repeated random numbers php randomly generates a 4-digit verification code php randomly displays an image function php randomly displays an image example php generates a random password example generate a random user name and password php the function is used to generate random user names in batches. The php program uses php to generate random numbers randomly. the Function uses PHP to generate a random number. The php code generates a random number. example php generate random string function php random password generation function php generate random password function PHP generate random string function php generate random password several methods to generate random password |