Copy codeThe Code is as follows:
<? Php
//-------------------------------------
// File Description: mathematical operation Verification Code
// File Author: Jesse Lee
// Last updated: 2008-09-07
//-------------------------------------
Session_start ();
$ Sessionvar = 'vdcode'; // Session variable name
$ Width = 150; // Image width
$ Height = 20; // Image height
$ Operator = '+-*'; // operator
$ Code = array ();
$ Code [] = mt_rand (1, 9 );
$ Code [] = $ operator {mt_rand (0, 2 )};
$ Code [] = mt_rand (1, 9 );
$ Code [] = $ operator {mt_rand (0, 2 )};
$ Code [] = mt_rand (1, 9 );
$ Codestr = implode ('', $ code );
Eval ("\ $ result =". implode ('', $ code ).";");
$ Code [] = ';
$ _ SESSION [$ sessionvar] = $ result;
$ Img = ImageCreate ($ width, $ height );
ImageColorAllocate ($ img, mt_rand (230,250), mt_rand (230,250), mt_rand (230,250 ));
$ Color = ImageColorAllocate ($ img, 0, 0, 0 );
$ Offset = 0;
Foreach ($ code as $ char ){
$ Offset + = 20;
$ Txtcolor = ImageColorAllocate ($ img, mt_rand (0,255), mt_rand (0,150), mt_rand (0,255 ));
ImageChar ($ img, mt_rand (3, 5), $ offset, mt_rand (1, 5), $ char, $ txtcolor );
}
For ($ I = 0; I I <100; $ I ++ ){
$ Pxcolor = ImageColorAllocate ($ img, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
ImageSetPixel ($ img, mt_rand (0, $ width), mt_rand (0, $ height), $ pxcolor );
}
Header ('content-type: image/png ');
ImagePng ($ img );
?>