Php verification code generation program
<? Php
$ Consts = 'bcdfghjkmnpqrstwxyz ';
$ Vowels = 'aei23456789 ';
For ($ x = 0; $ x <6; $ x ++)
{
$ Const [$ x] = substr ($ consts, mt_rand (0, strlen ($ consts)-1), 1 );
$ Vow [$ x] = substr ($ vowels, mt_rand (0, strlen ($ vowels)-1), 1 );
}
$ Radomstring = $ const [0]. $ vow [0]. $ const [2]. $ const [1]. $ vow [1]. $ const [3]. $ vow [3]. $ const [4];
$ _ SESSION ['checkcode'] = $ string = substr ($ radomstring,); // only display 4 str
/T up image, the first number is the width and the second is the height
$ ImageX = strlen ($ radomstring) * 5.5; // the image width
$ ImageY = 20; // the image height
$ Im = imagecreatetruecolor ($ imageX, $ imageY );
// Creates two variables to store color
$ Background = imagecolorallocate ($ im, rand (180,250), rand (180,250), rand (180,250 ));
$ ForegroundArr = array (imagecolorallocate ($ im, rand (0, 20), rand (0, 20), rand (0, 20 )),
Imagecolorallocate ($ im, rand (0, 20), rand (0, 10), rand (245,255 )),
Imagecolorallocate ($ im, rand (245,255), rand (0, 20), rand (0, 10 )),
Imagecolorallocate ($ im, rand (245,255), rand (0, 20), rand (245,255 )));
$ Foreground2 = imagecolorallocatealpha ($ im, rand (20,100), rand (20,100), rand (20,100), 80 );
$ Middleground = imagecolorallocate ($ im, rand (200,160), rand (200,160), rand (200,160 ));
$ Middleground2 = imagecolorallocatealpha ($ im, rand (180,140), rand (180,140), rand (180,140), 80 );
// Fill image with bgcolor
Imagefill ($ im, 0, 0, imagecolorallocate ($ im, 250,253,254 ));
// Writes string
Imagestring ($ im, 5, 3, floor (rand (0, 5)-1, $ string [0], $ foregroundArr [rand (0, 3)]);
Imagestring ($ im, 5, 13, floor (rand ()-1, $ string [1], $ foregroundArr [rand ()]);
Imagestring ($ im, 5, 23, floor (rand ()-1, $ string [2], $ foregroundArr [rand ()]);
Imagestring ($ im, 5, 33, floor (rand ()-1, $ string [3], $ foregroundArr [rand ()]);
For ($ I = 0; $ I <strlen ($ string); $ I ++)
{
If (mt_rand (0, ord (substr ($ string, $ I, 1) % 2 = 0)
{
$ String {$ I} = '';
}
}
Imagestring ($ im, 2, 2, 0, $ string, $ foreground2 );
// Strikethrough
$ Border = imagecolorallocate ($ im, 133,153,193 );
// Imagefilledrectangle ($ aimg, 0, 0, $ x_size-1, $ y_size-1, $ back );
Imagerectangle ($ im, 0, 0, $ imageX-1, $ imageY-1, $ border );
$ Pointcol = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
For ($ I = 0; $ I <20; $ I ++)
{
Imagesetpixel ($ im, rand (2, $ imageX-2), rand (2, $ imageX-2), $ pointcol );
}
// Rotate
$ Middleground = imagecolorallocatealpha ($ im, rand (160,200), rand (160,200), rand (160,200), 80 );
// Random shapes
For ($ x = 0; $ x <15; $ x ++)
{
If (mt_rand (0, $ x) % 2 = 0)
{
Imageline ($ im, rand (0,120), rand (0,120), rand (0,120), rand (0,120), $ middleground );
Imageellipse ($ im, rand (0,120), rand (0,120), rand (0,120), rand (0,120), $ middleground2 );
}
Else
{
Imageline ($ im, rand (0,120), rand (0,120), rand (0,120), rand (0,120), $ middleground2 );
Imageellipse ($ im, rand (0,120), rand (0,120), rand (0,120), rand (0,120), $ middleground );
}
}
// Output to browser
Header ("content-type: image/png \ r \ n ");
Imagepng ($ im );
Imagedestroy ($ im );
?>