The php Verification Code Program is a php verification code program function. The principle is to use the php gd library to generate random numbers, and then create a session and a digital image, which becomes a graphical verification code.
Php tutorial Verification Code Program
A php verification code program function. The principle is to use the php gd library to generate a random number, and then create a session and a digital image, which becomes a graphical verification code.
*/
Function fun_code ($ sessionname)
{
Header ("content-type: image/png ");
Session_start ();
$ Authnum_session = '';
// $ Str = 'abcdefghijkmnpqrstuvwxyz1234567890 ';
$ Str = '000000 ';
$ L = strlen ($ str );
For ($ I = 1; $ I <= 4; $ I ++)
{
$ Num = rand (0 L-1 );
$ Authnum_session. = $ str [$ num];
}
$ _ Session [$ sessionname] = $ authnum_session;
Srand (double) microtime () * 1000000 );
$ Im = imagecreate (50, 20 );
$ Black = imagecolorallocate ($ im, 0, 0 );
$ White = imagecolorallocate ($ im, 255,255,255 );
$ Gray = imagecolorallocate ($ im, 200,200,200 );
Imagefill ($ im, 68, 30, $ gray );
For ($ I = 0; $ I <3; $ I ++)
{
Imageline ($ im, rand (), rand (), rand (20, 40), rand (), $ li );
}
Imagestring ($ im, 5, 8, 2, $ authnum_session, $ white );
For ($ I = 0; $ I <90; $ I ++)
{
Imagesetpixel ($ im, rand () % 70, rand () % 30, $ gray );
}
Imagepng ($ im );
Imagedestroy ($ im );
}
Echo fun_code ("code ");