- // +------------------------------------------------------------------------
- Verification code class, the object of this class can dynamically get verification code picture, verify code word characters in session[' code ')
- // +------------------------------------------------------------------------
- Supports 4-format alphanumeric character blending
- // +------------------------------------------------------------------------
- @Author: Hellochina (sanzi0930@163.com)
- // +------------------------------------------------------------------------
- @Date: June 7, 2012 11:03:00
- // +------------------------------------------------------------------------
- @version 1.0
- // +------------------------------------------------------------------------
- Class vcode{
- protected $width; Verification Code width
- protected $height; Verification Code length
- protected $codeNum; Number of verification code characters
- protected $codeType; Verification code type
- protected $fontSize; Character size
- protected $fontType; Font type
- protected $codeStr; Chinese content
- protected $strNum; Number of Chinese
- protected $imageType; Output Picture Type
- protected $image; Picture Resources
- protected $checkCode; Verification Code Content
- /**
- +--------------------------------------------------------------------------------
- * Get Verification Code information
- +--------------------------------------------------------------------------------
- * @param integer $width Verification code width
- * @param integer $height Verification Code height
- * @param integer $codeNum number of verification code characters
- * @param integer $codeType Verification code character Type 1 is the number 2 is the letter 3 is the Chinese character 4 is mixed
- * @param the size of the integer $fontSize captcha font
- * @param string $fontType captcha font type
- * @param string $imageType Verification code output picture type
- * @param string $codestr Chinese verification Code content
- +--------------------------------------------------------------------------------
- */
- Public function __construct ($width =100, $height =50, $codeNum =4, $codeType =4, $fontSize =12, $fontType = ' Heiti.ttf ', $ Imagetype= ' jpeg ', $codeStr = ' Go to me hungry man he's a oh flat ah yes fly a good look at the think just you? '}
- $this->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 ();
- }
- //+--------------------------------------------------------------------------------
- * Generate Verification Code characters
- //+--------------------------------------------------------------------------------
- * @return String
- //+--------------------------------------------------------------------------------
- Public Function __tostring () {
- $string = Implode (' ', $this->getcheckcode ());
- $_session["code"]= $string; Add to the session
- $this->getimage (); Output Verification Code
- Return ';
- }
- protected function Getcheckcode () {
- $string = Array ();
- Switch ($this->codetype) {
- Case 1:
- Numeric string
- $string = Array_rand (range (0,9), $this->codenum);
- Break
- Case 2:
- Large Letter String
- $string = Array_rand (Array_flip (Range (' A ', ' Z ')), $this->codenum);
- Break
- Case 3:
- Kanji string
- for ($i =0; $i < ($this->codenum); $i + +) {
- $start = Mt_rand (0, $this->strnum);
- $string [$i]= self::msubstr ($this->codestr, $start);
- }
- Break
- Case 4:
- Mixed string
- for ($i =0; $i < ($this->codenum); $i + +) {
- $rand =mt_rand (0,2);
- Switch ($rand) {
- Case 0:
- $ascii = Mt_rand (48,57);
- $string [$i] = sprintf ('%c ', $ascii);
- Break
Copy Code
|
Verification Code, PHP This topic was moved by Beckham on 2015-11-18 08:23