Ec (2); php Chinese and English Verification code Program $ code & quot; & nbsp; for ($ i0; $ I & lt; 4; $ I ++) {& nbsp; & nbsp; $ Ximt_rand (0, strlen ($ str) 2); & nbsp; & nb script ec (2); script
Php Chinese and English Verification Code Program
$ Code = "";
For ($ I = 0; $ I <4; $ I ++ ){
$ Xi = mt_rand (0, strlen ($ str)/2 );
If ($ Xi % 2) $ Xi + = 1;
$ Code. = substr ($ str, $ Xi, 2 );
}
$ _ SESSION ['code'] = $ code; // assign a value to the SESSION
$ Im = imagecreatetruecolor ($ w, $ h );
$ Bkcolor = imagecolorallocate ($ im, 250,250,250 );
Imagefill ($ im, 0, 0, $ bkcolor );
/*** Add interference ***/
For ($ I = 0; $ I <15; $ I ++ ){
$ Fontcolor = imagecolorallocate ($ im, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagearc ($ im, mt_rand (-10, $ w), mt_rand (-10, $ h), mt_rand (30,300), mt_rand (20,200), 55,44, $ fontcolor );
}
For ($ I = 0; I I <255; $ I ++ ){
$ Fontcolor = imagecolorallocate ($ im, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagesetpixel ($ im, mt_rand (0, $ w), mt_rand (0, $ h), $ fontcolor );
}
*********/
For ($ I = 0; $ I <4; $ I ++ ){
$ Fontcolor = imagecolorallocate ($ im, mt_rand (0,120), mt_rand (0,120), mt_rand (0,120); // This ensures that the random color is darker.
$ Codex = iconv ("GB2312", "UTF-8", substr ($ code, $ I ));
Imagettftext ($ im, mt_rand (20, 24), mt_rand (-60, 60), 40 * $ I + 20, mt_rand (30, 35), $ fontcolor, $ fontface, $ codex );
}
Imagepng ($ im );
?>