您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP图片验证码类

2025/8/16 8:05:12发布18次查看
验证码
x = $x;
$this->y = $y = 6;
$this->numchars = $numchars = 4; //number of code
$this->code = $code;
$this->width = $width = 80; //width of image
$this->height = $height = 25; //height of image
$this->bg = $bg = 255 255 255; //rgb color of background
$this->coltxt = $coltxt = 0 0 0 0; //rgb color of code
$this->border = $colborder = 100 100 100; //rgb color of border
$this->numcirculos = $numcirculos = 800; //number of random point
}
//create base image
function createimage()
{
//create a image
$im = imagecreate ($this->width, $this->height) or die (cannot initialize new gd image stream);
//get the rgb color code
$colorbg = explode( , $this->bg);
$colorborder = explode( , $this->border);
$colortxt = explode( , $this->coltxt);
//put the background color on the image
$imbg = imagecolorallocate ($im, $colorbg[0], $colorbg[1], $colorbg[2]);
//put the border on the image
$border = imagecolorallocate($im, $colorborder[0], $colorborder[1], $colorborder[2]);
$imborder = imagerectangle($im, 0, 0, $this->width-1,$this->height-1, $border);
//put the code color on the image
$imtxt = imagecolorallocate ($im, $colortxt[0], $colortxt[1], $colortxt[2]);
//drop 800 points
for($i = 0; $i numcirculos; $i++)
{
$impoints = imagesetpixel($im, mt_rand(0,80), mt_rand(0,80), $border);
}
//put the code on image
for($i = 0; $i numchars; $i++)
{
//get $x's location
$this->x = 21 * $i + 5;
//get the code
mt_srand((double) microtime() * 1000000*getmypid());
$this->code.= (mt_rand(0, 9));
$putcode = substr($this->code, $i, 1);
//put the code;
$code = imagestring($im, 5, $this->x, $this->y, $putcode,$imtxt);
}
return $im;
}
//transfer the code to next page
function transfercode()
{
//get the code
$this->createimage();
$vcode = $this->code;
session_start();
session_register(vcode);
$_session['validate_code'] = $vcode;
return $vcode;
}
//display the image
function show()
{
header(content-type:image/png);
imagepng($this->createimage());
imagedestroy($this->createimage());
}
}
?>
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product