- Session_start ();
- $ Type = 'GIF ';
- $ Width = 56;
- $ Height = 22;
- Header ("Content-type: image/". $ type );
- Srand (double) microtime () * 1000000 );
- $ Randval = randStr (4, "NUMBER ");
- If ($ type! = 'GIF' & function_exists ('imagecreatetruecolor ')){
- $ Im = @ imagecreatetruecolor ($ width, $ height );
- } Else {
- $ Im = @ imagecreate ($ width, $ height );
- }
- $ R = Array (225,211,255,223 );
- $ G = Array (225,236,237,215 );
- $ B = Array (225,236,166,125 );
-
- $ Key = rand (0, 3 );
-
- $ BackColor = ImageColorAllocate ($ im, $ r [$ key], $ g [$ key], $ B [$ key]); // background color (random)
- $ BorderColor = ImageColorAllocate ($ im, 0, 0, 0); // border color
- $ PointColor = ImageColorAllocate ($ im, 255,170,255); // vertex color
-
- @ Imagefilledrectangle ($ im, 0, 0, $ width-1, $ height-1, $ backColor); // background position
- @ Imagerectangle ($ im, 0, 0, $ width-1, $ height-1, $ borderColor); // border position
- $ StringColor = ImageColorAllocate ($ im, 153 );
-
- For ($ I = 0; $ I <= 100; $ I ++ ){
- $ PointX = rand (2, $ width-2 );
- $ PointY = rand (2, $ height-2 );
- @ Imagesetpixel ($ im, $ pointX, $ pointY, $ pointColor );
- }
-
- @ Imagestring ($ im, 16, 10, 2, $ randval, $ stringColor );
- $ ImageFun = 'image'. $ type;
- $ ImageFun ($ im );
- @ ImageDestroy ($ im );
- $ _ SESSION ['validatecode'] = $ randval;
- // Generate a random string
- Function randStr ($ len = 6, $ format = 'all '){
- Switch ($ format ){
- Case 'all ':
- $ Chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 '; break;
- Case 'char ':
- $ Chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy'; break;
- Case 'number ':
- $ Chars = '20140901'; break;
- Default:
- $ Chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 ';
- Break;
- }
- $ String = "";
- While (strlen ($ string) <$ len)
- $ String. = substr ($ chars, (mt_rand () % strlen ($ chars), 1 );
- Return $ string;
- }
- ?>
|