Home > php教程 > PHP源码 > body text

验证码类 支持数字,字母,汉字,混合

PHP中文网
Release: 2016-05-25 17:11:08
Original
1020 people have browsed it


width	 =  $width;
			$this->height 	 =  $height;
			$this->codeNum 	 =  $codeNum;
			$this->codeType	 =  $codeType;
			$this->fontSize  =  $fontSize;
			$this->fontType	 =  $fontType;
			$this->codeStr	 =  $codeStr;
			$this->strNum = strlen($this->codeStr)/3-1;
			$this->imageType =  $imageType;
			$this->checkCode =  $this->getCheckCode();
		}

      //+--------------------------------------------------------------------------------
      //* 生成验证码字符
      //+--------------------------------------------------------------------------------
      //* @return string
      //+--------------------------------------------------------------------------------
		public function __toString(){			
			$string = implode('', $this->getCheckCode());
			$_SESSION["code"]=$string;  //加到session中
			$this->getImage();              //输出验证码
			return '';
		}	
		protected function getCheckCode(){
			$string = array();				
			switch($this->codeType){
				case 1:
					//数字字符串
					$string =  array_rand(range(0,9), $this->codeNum);
					break;
				case 2:
					//大字母字符串
					$string = array_rand(array_flip(range('A', 'Z')), $this->codeNum);
					break;
				case 3:
					//汉字字符串
					
					for($i=0; $icodeNum); $i++){
						$start = mt_rand(0, $this->strNum);
						$string[$i]= self::msubstr($this->codeStr,$start);
					}
					break;
				case 4:
					//混合字符串
					for($i=0; $icodeNum); $i++){
						$rand=mt_rand(0,2);
						switch($rand){
							case 0:
								$ascii = mt_rand(48,57);
								$string[$i] = sprintf('%c',$ascii);
								break;
Copy after login

                       

           

2. [图片] 混合.jpg验证码类 支持数字,字母,汉字,混合    

验证码类 支持数字,字母,汉字,混合

                       

           

3. [图片] 数字.jpg验证码类 支持数字,字母,汉字,混合    

验证码类 支持数字,字母,汉字,混合

                       

           

4. [图片] 中文.jpg验证码类 支持数字,字母,汉字,混合    

验证码类 支持数字,字母,汉字,混合

                       

           

5. [图片] 字母.jpg验证码类 支持数字,字母,汉字,混合    

验证码类 支持数字,字母,汉字,混合

                       

                   



                           

       

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template