www.gusucode.com > 图片存储_淘宝相册_免费网盘源代码 > imgcode.php

    <?php
session_start();
function random($lenrn)
{
$strcode="abckdefghijklmnopqrstuvwxyz0123456789";
mt_srand();
$strran="";
for($i=0;$i<$lenrn;$i++){
$strran.=$strcode[mt_rand(0,35)];
}
return strtoupper($strran);
}
$str=random(4); //随机生成的字符串
$width = 50; //验证码图片的宽度
$height = 25; //验证码图片的高度
@header("Content-Type:image/png");
$_SESSION["code"] = $str;
$image=imagecreate($width,$height);
//背景颜色
$back=imagecolorallocate($image,0xFF,0xFF,0xFF);
//模糊点颜色
$pix=imagecolorallocate($image,187,230,247);
//字体颜色
$font=imagecolorallocate($image,41,163,238);
//绘模糊作用的点
mt_srand();
for($i=0;$i<1000;$i++)
{
imagesetpixel($image,mt_rand(0,$width),mt_rand(0,$height),$pix);
}
imagestring($image, 5, 7, 5,$str, $font);
imagerectangle($image,0,0,$width-1,$height-1,$font);
imagepng($image);
imagedestroy($image);
?>