php生成验证码详细教程
//header("content-type:image/png");
$num ='1234';
$imagewidth=60;
$imageheight=18;$numimage = imagecreate($imagewidth,$imageheight);
imagecolorallocate($numimage,240,240,240);
for($i=0;$i$x = mt_rand(1,8)+$imagewidth*$i/4;
$y = mt_rand(1,$imageheight/4);
$color=imagecolorallocate($numimage,mt_rand(0,150),mt_rand(0,150),mt_rand(0,150));
imagestring($numimage,5,$x,$y,$num[$i],$color);
}for($i=0;$i $randcolor=imagecolorallocate($numimage,rand(200,255),rand(200,255),rand(200,255));
imagesetpixel($numimage,rand()%70,rand()%20,$randcolor);
}
imagepng($numimage);
imagedestroy($numimage);
?>
来看一款生成验证码实例
//生成验证码图片
session_start();
header("content-type: image/png");
srand((double)microtime()*1000000);
$roundnum=rand(1000,9999);
//把随机数存入session以便以后用
$_session["sessionround"]=$roundnum;
$im = imagecreate(58,28);
$red = imagecolorallocate($im, 255,0,0);
$blue = imagecolorallocate($im, 0,255,0);
//局域填充,相当于背景
imagefill($im,68,30,$red);
//将四位整数验证码绘入图片
imagestring($im, 5, 10, 8, $roundnum, $blue);
for($i=0;$i
{
imagesetpixel($im, rand()%70 , rand()%30 , $black);
}
imagepng($im);
imagedestroy($im);
?>
html调用 方法
验证码
上一篇: RBP系统管理之用户审批