|
If (! Isset ($ _ SESSION) {// checks whether the session is enabled
Session_start (); // enable session
}
$ Width = 70; // width of the canvas
$ Height = 25; // canvas height
$ Length = 4; // verification code length
$ Code = getcode ($ length); // Obtain a random string
$ _ SESSION ['verfycode'] = $ code;
$ Img = imagecreate ($ width, $ height );
$ Bgcolor = imagecolorallocate ($ img, 240,240,240 );
$ Rectangelcolor = imagecolorallocate ($ img, 150,150,150 );
Imagerectangle ($ img, $ width-1, $ height-1, $ rectangelcolor); // draw a border
For ($ I = 0; $ I <$ length; $ I ++) {// circular writing
$ Codecolor = imagecolorallocate ($ img, mt_rand (50,200), mt_rand (50,128), mt_rand (50,200 ));
$ Angle = rand (-20, 20 );
$ Charx = $ I * 15 + 8;
$ Chary = ($ height + 14)/2 + rand (-1, 1 );
Imagettftext ($ img, 15, $ angle, $ charx, $ chary, $ codecolor, 'C: WINDOWSFontsSIMKAI. ttf ',
$ Code [$ I]);
}
For ($ I = 0; $ I <20; $ I ++) {// looping
$ Linecolor = imagecolorallocate ($ img, mt_rand (0,250), mt_rand (0,250), mt_rand (0,250 ));
$ Linex = mt_rand (1, $ width-1 );
$ Liney = mt_rand (1, $ height-1 );
Imageline ($ img, $ linex, $ liney, $ linex + mt_rand ()-2, $ liney + mt_rand ()-2, $ linecolor );
}
For ($ I = 0; $ I <100; $ I ++) {// recurrence point
$ Pointcolor = imagecolorallocate ($ img, mt_rand (0,250), mt_rand (0,250), mt_rand (0,250 ));
Imagesetpixel ($ img, mt_rand (1, $ width-1), mt_rand (1, $ height-1), $ pointcolor );
}
Function getcode ($ length) {// Generate a php random number
$ Pattern = '1234567890abcdefghijklomnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz '; // character pool
For ($ I = 0; $ I <$ length; $ I ++ ){
$ Key. = $ pattern {mt_rand (0, 35 )};
}
Return $ key;
}
Ob_clean ();
Header ('content-type: image/png ');
Imagepng ($ img );
?> |