PHP Chinese-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 value to 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 <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);
}
/*********** content *********/
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 color of the random comes out darker.
$codex =iconv ("GB2312", "UTF-8", substr ($code, $i *2,2));
Imagettftext ($im, Mt_rand (20,24), Mt_rand ( -60,60), 40* $i +20,mt_rand (30,35), $fontcolor, $fontface, $codex);
}
Imagepng ($im);
?>