php简单验证码实例

作者在 2011-07-31 18:26:57 发布以下内容
<?php
/*
* Created on 2011-7-31
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
for($i=0;$i<4;$i++){
     $rand.=rand(1,9);
}
$b=imagecreate(130,40);//建个图像
imagecolorallocate($b,0,0,0);//设置图像颜色
$color=imagecolorallocate($b,255,255,255);//设置图像字体颜色
for($i=0;$i<3;$i++){
    $color2=imagecolorallocate($b,rand(0,255),rand(0,255),rand(0,255));//设置图像随机颜色

    $b2=imageline($b,rand(0,100),0,rand(0,255),40,$color2);//设置一个验证码线段
}
for($i=0;$i<200;$i++){
    imagesetpixel($b,rand()%130,rand()%40,$color2);//设置验证码的点
}
imagestring($b,4,12,12,$rand,$color);//将字体写如图像中
header("content-type:image/gif");
imagegif($b);//输出这个图像

?>
默认分类 | 阅读 892 次
文章评论,共0条
游客请输入验证码