-
- /**
- * Verification code
- */
- Class Base_Tool_Verify {
- /**
- * Verification code generation method
- */
- Public static function createCode (){
- // Generate a verification code Image
- // All numbers
- $ Str = "D, B, 2, 3, 4, 5, 6, 8, 9, A, B, C, D, E, F, G, H, W, J, K, M, m, N, K, P, Q, R, S, T, U, V, W, X, Y, Z "; // you can add or delete the characters to be displayed.
- $ List = explode (",", $ str );
- $ Cmax = count ($ list)-1;
- $ VerifyCode = '';
- For ($ I = 0; $ I <4; $ I ++ ){
- $ Randnum = mt_rand (0, $ cmax );
- $ VerifyCode. = $ list [$ randnum]; // extract the characters and combine them into the verification code characters.
- }
- $ _ SESSION ['code'] = $ verifyCode; // put the characters in the SESSION
-
- $ Im = imagecreate (); // generate an image
- $ Black = imagecolorallocate ($ im, 0, 0, 0); // set the color of the bar and the following three items
- $ White = imagecolorallocate ($ im, 244,249,244 );
- $ Gray = imagecolorallocate ($ im, rand (200,255), rand (200,255), rand (200,255 ));
- $ Red = imagecolorallocate ($ im, rand (200,255), rand (200,255), rand (200,255 ));
- $ Rand_color = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
- $ Rand_color2 = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
- Imagefill ($ im, $ white); // fill the color of the image
- $ Pix = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
- Mt_srand ();
- For ($ I = 0; I I <100; $ I ++)
- {
- Imagesetpixel ($ im, mt_rand (0,180), mt_rand (), $ pix );
- }
- Imageline ($ im, 0, rand (0, 28), 80, rand (0, 28), $ rand_color );
- Imageline ($ im, 0, rand (0, 28), 80, rand (0, 28), $ rand_color2 );
-
- // Print the verification code into the image
- $ Mycolor = imagecolorallocate ($ im, 0, 78,152 );
- $ Path = API_PATH.DS. 'base'. DS. 'tool ';
- Putenv ('gdfontpath = '. $ path );
- $ Font = 'simhei. ttf ';
- $ Arrstr = str_split ($ verifyCode );
- Imagettftext ($ im, 20, rand (0, 50), 10, rand (20, 30), $ mycolor, $ font, $ arrstr [0]);
- Imagettftext ($ im, 15, rand (0, 50), 20, rand (20, 30), $ mycolor, $ font, $ arrstr [1]);
- Imagettftext ($ im, 15, rand (0, 50), 30, rand (20, 30), $ mycolor, $ font, $ arrstr [2]);
- Imagettftext ($ im, 15, rand (0, 50), 40, rand (20, 30), $ mycolor, $ font, $ arrstr [3]);
- $ Font2 = imagecolorallocate ($ im, 41,163,238 );
- Imagerectangle ($ im, 0, 0, 1, 1, $ font2 );
- Imagepng ($ im );
- Imagedestroy ($ im );
- }
- }
|