<?
/**
* Verification Code
* 2011/8/21
* Kcj
**/
Include "isLogin. php ";
// Generate a 4-digit Verification Code randomly
$ Num = '';
For ($ I = 0; $ I <4; $ I ++ ){
$ Num. = dechex (rand (); // The dechex function is a decimal transfer binary.
}
Session_start (); // enable session
$ _ SESSION ['yanzheng'] = $ num; // use session to remember this verification number.
Header ("Content-type: image/PNG ");
$ Im = imagecreate (60, 20); // create a canvas
$ Back = imagecolorallocate ($ im, rand (); // create a background color (black)
$ Gray = imagecolorallocate ($ im, rand (0,255), rand (0,200), rand (0, 55); // (white)
Imagefill ($ im, 0, 0, $ gray); // fill color
$ Style = array ($ back, $ gray, $ gray); // generates an array
Imagesetstyle ($ im, $ style); // you can specify the image style.
$ Y1 = rand (0, 20 );
$ Y2 = rand (0, 20 );
$ Y3 = rand (0, 20 );
$ Y4 = rand (0, 20 );
Imageline ($ im, 0, $ y1, 60, $ y3, IMG_COLOR_STYLED); // draw a line
Imageline ($ im, 0, $ y2, 60, $ y4, IMG_COLOR_STYLED );
// A large number of black spots are randomly generated on the canvas, which can interfere with the canvas.
For ($ I = 0; $ I <80; $ I ++ ){
Imagesetpixel ($ im, rand (0, 60), rand (0, 20), $ back );
}
$ Str = rand (3, 8 );
For ($ I = 0; $ I <4; $ I ++ ){
$ Strp = rand (1, 6 );
Imagestring ($ im, 6, $ str, $ strp, substr ($ num, $ I, 1), $ back );
$ Str + = rand (8, 12 );
}
ImagePNG ($ im );
Imagedestroy ($ im );
?>
From chaojie2009