<无详细内容>
- /**
- * Verification Code Class
- */
- Class base_tool_verify{
- /**
- * Generate Verification Code method
- */
- public static function Createcode () {
- Generate a Captcha picture
- Full Digital
- $str = "D,b,2,3,4,5,6,7,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"; To display the characters, you can make additions and deletions
- $list = Explode (",", $str);
- $cmax = count ($list)-1;
- $verifyCode = ";
- for ($i =0; $i < 4; $i + +) {
- $randnum = Mt_rand (0, $cmax);
- $verifyCode. = $list [$randnum]; Take out the characters and combine them into the captcha characters we want.
- }
- $_session[' Code ' = $verifyCode; Put characters in session
- $im = Imagecreate (80,28); Create a picture
- $black = imagecolorallocate ($im, 0, 0, 0); This bar and the following three are set for the color
- $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, 0,0, $white); Fill a picture with color
- $pix =imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
- Mt_srand ();
- for ($i =0; $i <100; $i + +)
- {
- Imagesetpixel ($im, Mt_rand (0,180), Mt_rand (0,35), $pix);
- }
- Imageline ($im, 0,rand (0,28), N, Rand (0,28), $rand _color);
- Imageline ($im, 0,rand (0,28), N, Rand (0,28), $rand _color2);
- Draw a verification code into a picture
- $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, 0,50, Rand (20,30), $mycolor, $font, $arrstr [0]);
- Imagettftext ($im, 0,50, Rand (20,30), $mycolor, $font, $arrstr [1]);
- Imagettftext ($im, 0,50, Rand (20,30), $mycolor, $font, $arrstr [2]);
- Imagettftext ($im, Max, Rand (0,50), Max, Rand (20,30), $mycolor, $font, $arrstr [3]);
- $font 2=imagecolorallocate ($im, 41,163,238);
- Imagerectangle ($im, 0,0,1,1, $font 2);
- Imagepng ($im);
- Imagedestroy ($im);
- }
- }
Copy Code |