中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

驗證碼PHP類 支持數字,字母,漢字,混合

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
<?php
// +------------------------------------------------------------------------
// 驗證碼類,該類的對象能動態(tài)獲取驗證碼圖片,驗證碼字符保存在SESSION['code']中 
// +------------------------------------------------------------------------
// 支持4種格式 數字 字母 漢字 混合
// +------------------------------------------------------------------------
// @Author: HelloChina(sanzi0930@163.com)                           
// +------------------------------------------------------------------------
// @Date: 2012年6月7日11:03:00                  
// +------------------------------------------------------------------------
// @version 1.0                                                     
// +------------------------------------------------------------------------

    class Vcode{
        protected $width;               //驗證碼寬度
        protected $height;              //驗證碼長度
        protected $codeNum;             //驗證碼字符個數
        protected $codeType;                //驗證碼類型
        protected $fontSize;                //字符大小
        protected $fontType;                //字體類型
        protected $codeStr;             //中文內容
        protected $strNum;              //中文個數
        protected $imageType;               //輸出圖片類型
        protected $image;               //圖片資源
        protected $checkCode;               //驗證碼內容
     /**
      +--------------------------------------------------------------------------------
      * 取得驗證碼信息
      +--------------------------------------------------------------------------------
      * @param integer $width       驗證碼寬度 
      * @param integer $height      驗證碼高度 
      * @param integer $codeNum     驗證碼字符個數 
      * @param integer $codeType    驗證碼字符類型 1為數字 2為字母 3為漢字 4為混編
      * @param integer $fontSize        驗證碼字體的大小
      * @param string  $fontType    驗證碼字體類型
      * @param string  $imageType   驗證碼輸出圖片類型
      * @param string  $codestr     中文驗證碼內容
      +--------------------------------------------------------------------------------
     */
        public function __construct($width=100, $height=50, $codeNum=4, $codeType=4, $fontSize=12, $fontType='heiti.ttf' ,$imageType='jpeg', $codeStr='去我餓人他一哦平啊是的飛個好就看了在想才吧你嗎'){
            $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();
        }

      //+--------------------------------------------------------------------------------
      //* 生成驗證碼字符
      //+--------------------------------------------------------------------------------
      //* @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; $i<($this->codeNum); $i++){
                        $start = mt_rand(0, $this->strNum);
                        $string[$i]= self::msubstr($this->codeStr,$start);
                    }
                    break;
                case 4:
                    //混合字符串
                    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;

標簽:

版權申明:本站文章部分自網絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:常用的C#類

下一篇:WebGIS中一些功能算法實例