//

国产伦精品一区二区三区视频1,2020久热爱精品视频在线观看,91黄色国产精品,全集草久热的视频在线观看高清播放,精品国产在线免费视频,国产精品日韩高清伦字幕搜索,午夜作爱无码视频全集高清,国产精品成av电影不卡,免费成品网站源码1688免费推荐全集在线

Information for details

php常用類分享之驗證碼圖片類

驗證碼生成類:

功能:生成驗證碼。

本文實例講述了PHP實現(xiàn)的簡單驗證碼類及其詳細的使用方法。分享給大家供大家參考,具體如下

<?php

/**
 * 驗證碼圖片類
*/

class verify{

    //聲明成員屬性          
    private $width; //寬
    private $height; //高
    private $imagetype; //圖片類型
    private $num; //顯示字符的個數(shù)
    private $checkcode; //返回給session 的字符串
    private $img; //定義一個圖片資源
    private $type; //驗證碼的類型 ,1 數(shù)字 2 字母 3 組合型
    
    //初始化 默認的參數(shù)
    public function __construct($width='100',$height='30',$num='4',$type='3',$imagetype='jpeg'){
        $this->width=$width;
        $this->height=$height;
        $this->num=$num;
        $this->type=$type;
        $this->imagetype=$imagetype;
        $this->checkcode=$this->getcheckcode();
    }
    
    private function getcheckcode(){ //產(chǎn)生字符串的方法
        switch($this->type){
            case 1://數(shù)字類型的
                $string=join('',array_rand(range(0,9),$this->num));
            break;
            case 2://字母類型的
                $string=implode('',array_rand(array_flip(range('a','z')),$this->num));
            break;
            case 3://字母與數(shù)字混合性
                $str='23456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
                $s=str_shuffle($str);
                $string=substr($s,0,$this->num);
            break;
        }
        return $string;
    }

    //定義產(chǎn)生畫布的方法
    private function createimage(){
        $this->img=imagecreatetruecolor($this->width,$this->height);
    }
    
    //產(chǎn)生背景顏色,顏色要比字體的顏色淺
    private function bgcolorrand(){
        return imagecolorallocate($this->img,mt_rand(230,255),mt_rand(230,255),mt_rand(230,255));
    }
    
    //產(chǎn)生字體的顏色,顏色要比背景顏色深
    private function textcolorrand(){
        return imagecolorallocate($this->img,mt_rand(0,125),mt_rand(0,125),mt_rand(0,125));
    }
    
    //填充背景的顏色
    private function filledbg(){
        imagefilledrectangle($this->img,0,0,$this->width,$this->height,$this->bgcolorrand());
    }
    
    //添加干擾點
    private function filledpix(){
        for($i;$i<70;$i++){
            $x=mt_rand(2,$this->width-5);
            $y=mt_rand(2,$this->height-5);
            imagesetpixel($this->img,$x,$y,$this->textcolorrand());
        }
    }
    
    //循環(huán)寫上字符
    private function writetext(){
        for($i=0;$i<$this->num;$i++){
            $x=ceil($this->width/$this->num)*$i+5;
            $y=mt_rand(5,$this->height-20);
            imagechar($this->img,5,$x,$y,$this->checkcode[$i],$this->textcolorrand());
        }
    }
    
    //輸出圖片
    private function output(){
        $func='image'.$this->imagetype;
        $header='content-type:image/'.$this->imagetype;
        /*----判斷我們鏈接的這個字符串的名字是不是函數(shù)----*/
        if(function_exists($func)){
            header($header);
            $func($this->img);
        }else{
            echo '當前系統(tǒng)不支持這種圖片的格式';
            return false;
        }
    }
    
    //獲得圖片的方法
    public function getimg(){
        $this->createimage();//創(chuàng)建畫布方法
        $this->filledbg();//填充背景方法
        $this->filledpix();//填充干擾點方法
        $this->writetext();//寫上隨機字符方法
        $this->output();//輸出圖片方法
    }

    function __get($proname){
        if($proname=='checkcode'){
            return $this->$proname;
        }else{
            return false;
        }
    }

    //銷毀圖片資源,自動執(zhí)行
    public function __destruct(){
        imagedestroy($this->img);
    }
}

$verify=new verify();
$verify->getimg();
?>


然成科技是一家本土的云南軟件開發(fā)公司,2017年獲得云南省科技廳、省財政廳、省稅務(wù)局等機構(gòu)認定的高新技術(shù)企業(yè)。定位于高端網(wǎng)站設(shè)計、系統(tǒng)開發(fā)、APP開發(fā)、微信公眾號、微信小程序開發(fā)。擁有多個軟著權(quán),公司先后為多家事業(yè)單位提供服務(wù),比如會澤文化館、宣威文化館、中科院昆明植物研究所等。其中中國科學(xué)院昆明植物研究所已經(jīng)進行了長達4年的合作,并且還持續(xù)合作中!

  • 滇公網(wǎng)安備 53010202001388號