Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1534278
  • 博文数量: 14
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 1424
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-28 15:27
文章分类

全部博文(14)

文章存档

2014年(3)

2010年(3)

2009年(2)

2008年(6)

我的朋友

分类:

2008-05-21 14:56:08

session_start();
function random($len)
{
$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
mt_srand();
$strs="";
for($i=0;$i<$len;$i++){
$strs.=$srcstr[mt_rand(0,35)];
}
return strtoupper($strs);
}
$str=random(4); //随机生成的字符串
$width = 45; //验证码图片的宽度
$height = 22; //验证码图片的高度
@header("Content-Type:image/png");
$_SESSION["code"] = $str;
//echo $str;
$im=imagecreate($width,$height);
//背景色
$back=imagecolorallocate($im,0xFF,0xFF,0xFF);
//模糊点颜色
$pix=imagecolorallocate($im,187,230,247);
//字体色
$font=imagecolorallocate($im,41,163,238);
//绘模糊作用的点
mt_srand();
for($i=0;$i<1000;$i++)
{
imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);
}
imagestring($im,5,7,5,$str,$font);
imagerectangle($im,0,0,$width-1,$height-1,$font);
imagepng($im);
imagedestroy($im);
?>
阅读(3992) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-07-20 22:01:16

顶你了,phpstudy是个好东西!!