Public Function code () {
Generate a Captcha picture
Header ("Content-type:image/png");
Full Digital
$str = "1,2,3,4,5,6,7,8,9,a,b,c,d,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"; To display the characters, you can make additions and deletions
$list = Explode (",", $str);
$cmax = count ($list)-1;
$verifyCode = ";
for ($i =0; $i < 5; $i + +) {
$randnum = Mt_rand (0, $cmax);
$verifyCode. = $list [$randnum]; Take out the characters and combine them into the captcha characters we want.
}
Session (' Code ', $verifyCode); Put characters in session
$im = Imagecreate (58,28); Create a picture
$black = Imagecolorallocate ($im, 0,0,0); This bar and the following three are set for the color
$white = Imagecolorallocate ($im, 255,255,255);
$gray = Imagecolorallocate ($im, 200,200,200);
$red = Imagecolorallocate ($im, 255, 0, 0);
Imagefill ($im, 0,0, $white); Fill a picture with color
Draw a verification code into a picture
Imagestring ($im, 5, 8, $verifyCode, $black); Write the captcha to the picture
for ($i =0; $i <50; $i + +)//Add interfering pixels
{
Imagesetpixel ($im, Mt_rand (0,120), Mt_rand (0,30), $black); Add dot-like interferon
Imagesetpixel ($im, Mt_rand (0,120), Mt_rand (0,30), $red);
Imagesetpixel ($im, Mt_rand (0,120), Mt_rand (0,30), $gray);
Imagearc ($im, Mt_rand (0,120), Mt_rand (0,30), (a), (a), A, $black); Add an arc-like interferon
Imageline ($im, Mt_rand (0,120), Mt_rand (0,30), Mt_rand (0,15), Mt_rand (0,15), $red); Add line-like interferon
// }}
}
Imagepng ($im);
Imagedestroy ($im);
}
<div class= "Fig_left" >
<div class= "Info" > Verification Code </div>
</div>
<input type= "text" class= "Input_register" name= "code"/>
PHP Generate Verification code