Three php Tutorials: Chinese Character English Verification Code Generation Program
$ ChineseChar = explode (',', "People, come, come, friends, learn, filial piety, benevolence, righteousness, courtesy, integrity, loyalty, country, medium, easy, white, who, fire, King, gold, wood, Thunder, wind, dragon, Tiger, day, earth, raw, dizzy, food, bird, field, three, hundreds, money, Fu, love, love, animal, insect, fish, nine, net, new, degree, ah, alas, ah, oh, Yi, old, less, day, month, Star, Ken, various, Cheng ");
$ K [0] = $ ChineseChar [array_rand ($ ChineseChar)];
$ K [1] = $ ChineseChar [array_rand ($ ChineseChar)];
$ K [2] = $ ChineseChar [array_rand ($ ChineseChar)];
$ K [3] = $ ChineseChar [array_rand ($ ChineseChar)];
$ Cookie_str = implode ('', $ k );
Setcookie ('vrify ', md5 ($ cookie_str), time () + 600 );
$ Str [0] = iconv ('gb2312', 'utf-8', $ k [0]);
$ Str [1] = iconv ('gb2312', 'utf-8', $ k [1]);
$ Str [2] = iconv ('gb2312', 'utf-8', $ k [2]);
$ Str [3] = iconv ('gb2312', 'utf-8', $ k [3]);
// Construct an image
$ X_size = 100;
$ Y_size = 25;
$ Font = 'simhei. ttf ';
$ Pic = imagecreate ($ x_size, $ y_size );
$ Background_color = imagecolorallocate ($ image, 255,255,255 );
$ ForegroundArr = array (imagecolorallocate ($ pic, rand (0, 20), rand (0, 20), rand (0, 20 )),
Imagecolorallocate ($ pic, rand (0, 20), rand (0, 10), rand (245,255 )),
Imagecolorallocate ($ pic, rand (245,255), rand (0, 20), rand (0, 10 )),
Imagecolorallocate ($ pic, rand (245,255), rand (0, 20), rand (245,255 )));
Imagettftext ($ pic, mt_rand (), mt_rand (-), 6, mt_rand (), $ foregroundArr [rand ()], $ font, $ str [0]);
Imagettftext ($ pic, mt_rand (), mt_rand (-), $ foregroundArr [rand ()], $ font, $ str [1]);
Imagettftext ($ pic, mt_rand (), mt_rand (-), $ foregroundArr [rand ()], $ font, $ str [2]);
Imagettftext ($ pic, mt_rand (), mt_rand (-), 66, mt_rand (), $ foregroundArr [rand ()], $ font, $ str [3]);
For ($ I = 0; $ I <80; $ I ++)
{
$ Pointcol = imagecolorallocate ($ pic, rand (0,255), rand (0,255), rand (0,255 ));
Imagesetpixel ($ pic, rand (2, $ x_size-2), rand (2, $ y_size-2), $ pointcol );
}
$ Border = imagecolorallocate ($ pic, 133,153,193 );
Imagerectangle ($ pic, 0, 0, $ x_size-1, $ y_size-1, $ border );
Imagepng ($ pic );
Imagedestroy ($ pic );
?>
1 2 3 4