PHP代码 -- 生成验证码(待完善)
<?php header('Content-type: image/png'); //图形的宽和高 $im_width = 75; $im_height = 25; //取随机的四位数 $nmsg = ''; for ($i = 0; $i < 4; $i++) { $nmsg .= dechex(rand(0, 15)); } //创建图形区域 $im = imagecreatetruecolor(75, 25); //填充图形背景色为白色 $white = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $white); //绘制验证码 $col = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)); imagestring($im, 5, 20, 4, $nmsg, $col); //绘制干扰线条 $num = rand(4,8); for($i=0;$i<$num;$i++){ $col = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)); imageline($im,rand(0,$im_width),rand(0,$im_height),rand(0,$im_width),rand(0,$im_height),$col); } //输出并销毁 imagepng($im); imagedestroy($im);