国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP圖片驗證碼類

2024-05-04 23:00:08
字體:
來源:轉載
供稿:網友

class validateimage
{

var $x;
var $y;
var $numchars;
var $code;
var $width;
var $height;
var $bg;
var $coltxt;
var $colborder;
var $numcirculos;

//構造函數、初始值
function validateimage()
{
$this->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 < $this->numcirculos; $i++)
{
$impoints = imagesetpixel($im, mt_rand(0,80), mt_rand(0,80), $border);
}

//put the code on image
for($i = 0; $i < $this->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());
}

}
?>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 铜梁县| 射阳县| 木里| 廉江市| 中超| 罗江县| 黄骅市| 乌恰县| 娄烦县| 乌拉特中旗| 班戈县| 吉木乃县| 修武县| 监利县| 台前县| 新乡市| 屏山县| 德惠市| 卓尼县| 盘锦市| 保山市| 同江市| 大足县| 扎囊县| 安新县| 宁都县| 敦化市| 崇仁县| 兴化市| 云和县| 丹东市| 金沙县| 开封县| 东乌珠穆沁旗| 阿拉善盟| 赤峰市| 金乡县| 汝城县| 色达县| 叙永县| 莱阳市|