您的位置:手机购彩平台 > 手机购彩平台-编程 > 可以加一个a标签

可以加一个a标签

2020-01-30 21:20

myvcode.class.php:封装创建验证码的类

/**构造方法实例化验证码对象,并初始化数据*@param int $width 设置默认宽度*@param int $height 设置默认高度*@param int $codeNum 设置验证码中的字符个数*@param int $pixNum 设置干扰点的个数*@param int $lineNum 设置干扰线的数量*/function __construct($width=80,$height=40,$codeNum=4,$pixNum=40,$lineNum=5){$this->width = $width;$this->height = $height;$this->codeNum = $codeNum;$this->pixNum = $pixNum;$this->lineNum = $lineNum;}/*内部私有方法,创建图像资源*/private function getCreateImage(){$this->image = imagecreatetruecolor($this->width, $this->height);$white = imagecolorallocate($this->image,0xff,0xff,0xff);imagefill($this->image, 0, 0, $white);$black = imagecolorallocate;imagerectangle($this->image, 0, 0, $this->width-1, $this->height-1, $black);}/*内部私有方法,绘制字符,去掉o0Llz和012*/private function createCheckCode(){$code = '3456789abcdefghijkmnpqrstuvwxyABCDEFGHIJKMNPQRSTUVWXY';$this->checkCode = "";for($i=0; $icodeNum;$i++){$char = $code{rand};$this->checkCode .= $char;$fontColor = imagecolorallocate($this->image, rand,rand;$fontSize = rand;$x = rand(0,$this->width-imagefontwidth;$y = rand(0,$this->height-imagefontheight;imagechar($this->image, $fontSize, $x, $y, $char, $fontColor);}}/*内部私有方法设置干扰元素*/private function setDisturbColor(){/*绘制干扰点*/for($i=0; $ipixNum; $i++){$color = imagecolorallocate($this->image, rand, rand;imagesetpixel($this->image, rand, rand, $color);}/*绘制干扰线*/for($i=0; $ilineNum; $i++){$color = imagecolorallocate($this->image, rand, rand;imageline($this->image, rand, rand,rand($this->width / 2,$this->width – 2), rand($this->height / 2,$this->height – 2), $color);

}}/*开启session保存 利用echo 输出图像*/function __toString(){$_SESSION['code'] = strtoupper;$this->getCreateImage();$this->createCheckCode();$this->setDisturbColor;}/*内部私有方法输出图像*/private function outputImg(){header("content-type:image/png");imagepng;}/*析构方法,释放对象*/function __destruct(){imagedestroy;}}?>

test.html:同过img标签引用

可以加一个a标签,用js实现换一张效果:

/*局部刷新换验证码*/function changeCode(){var imgcode = document.getElementById;var change = document.getElementById;change.onclick = function(){/*必须加后面的参数才能刷新*/imgcode.src='code.php?tm'+Math.random();}}

code和change分别是img和a的id

本文由手机购彩平台发布于手机购彩平台-编程,转载请注明出处:可以加一个a标签

关键词: