$num Random Number
$size Font Size
$width width
$height height
./tahoma.ttf for the displayed font
function Vcode ($num = 5, $size = A, $width = 50, $height) {
$width && $width = $num * $size * 4/5 + 5;
! $height && $height = $size + 10;
Removed 0 1 O l etc.
$str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW";
$code = ";
for ($i = 0; $i < $num; $i + +) {
$code. = $str [Mt_rand (0, strlen ($str)-1)];
}
echo $code;d ie;
Drawing images
$im = Imagecreatetruecolor ($width, $height);
Define the colors you want to use
$back _color = Imagecolorallocate ($im, 235, 236, 237);
$boer _color = Imagecolorallocate ($im, 118, 151, 199);
$text _color = imagecolorallocate ($im, Mt_rand (0, 120), Mt_rand (0, +), Mt_rand (0,));
Painting background
Imagefilledrectangle ($im, 0, 0, $width, $height, $back _color);
Draw Border
Imagerectangle ($im, 0, 0, $width-1, $height-1, $boer _color);
Draw interference Lines
for ($i = 0; $i < 5; $i + +) {
$font _color = imagecolorallocate ($im, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));
Imagearc ($im, Mt_rand (-$width, $width), Mt_rand (-$height, $height), Mt_rand ($width * 2), Mt_rand ($height * 2), M T_rand (0, Mt_rand), (0), $font _color);
}
Draw interference points
for ($i = 0; $i < $i + +) {
$font _color = imagecolorallocate ($im, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));
Imagesetpixel ($im, Mt_rand (0, $width), Mt_rand (0, $height), $font _color);
}
Draw the captcha here./tahoma.ttf to change the font for itself
$b = @imagefttext ($im, $size, 0, 5, $size + 3, $text _color, './tahoma.ttf ', $code);
Var_dump ($b);
$_session["Verifycode"] = $code;
echo $_session[' Verifycode '];d ie;
Header ("cache-control:max-age=1, s-maxage=1, No-cache, must-revalidate");
Header ("content-type:image/png;charset=gb2312");
Imagepng ($im);
Imagedestroy ($im);
}
Vcode ();
PHP Implementation Verification Code