create_code.php
<?php
Session_Start ();
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"; 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, Rand () p, rand () 0, $black); Add dot-like interferon
Imagesetpixel ($im, Rand () p, rand () 0, $red);
Imagesetpixel ($im, Rand () p, rand () 0, $gray);
Imagearc ($im, Rand () p, rand () p, a, A, a, $black); Add an arc-like interferon
Imageline ($im, Rand () p, rand () p, rand () p, rand () p, $red); Add line-like interferon
}
Imagepng ($im);
Imagedestroy ($im);
?>
PHP Generate Verification Code