老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)

PHP制作圖形驗(yàn)證碼

驗(yàn)證碼使用場(chǎng)景

我們?cè)陂_發(fā)系統(tǒng)的過(guò)程中,基本所有的系統(tǒng)都會(huì)涉及到登錄模塊,其中驗(yàn)證碼功能是這里面必不可少的一塊,是防止系統(tǒng)被爆破的有效途徑。所謂道高一尺魔高一丈,現(xiàn)在的驗(yàn)證碼越來(lái)越復(fù)雜先進(jìn),常見的字母數(shù)字驗(yàn)證碼,行為驗(yàn)證碼。本文詳細(xì)介紹簡(jiǎn)單的字母數(shù)字驗(yàn)證碼。

創(chuàng)新互聯(lián)于2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元朔城做網(wǎng)站,已為上家服務(wù),為朔城各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792

代碼

font = '/outputs/font/font.ttf';
    }

    //創(chuàng)建4個(gè)隨機(jī)碼
    private function createCode()
    {
        $_leng = strlen($this->charset) - 1;
        for ($i = 1; $i <= $this->codelen; $i++) {
            $this->code .= $this->charset[mt_rand(0, $_leng)];
        }
//        session_start();
//        $_SESSION['VerifyCode'] = strtolower($this->code);
        Session::set('VerifyCode', strtolower($this->code));
        return $this->code;
    }

    //創(chuàng)建背景
    private function createBg()
    {
        //創(chuàng)建畫布 給一個(gè)資源jubing
        $this->img = imagecreatetruecolor($this->width, $this->height);
        //背景顏色
        $color = imagecolorallocate($this->img, mt_rand(157, 255), mt_rand(157, 255), mt_rand(157, 255));
        //畫出一個(gè)矩形
        imagefilledrectangle($this->img, 0, $this->height, $this->width, 0, $color);
    }

    //創(chuàng)建字體
    private function createFont()
    {
        $_x = ($this->width / $this->codelen);   //字體長(zhǎng)度
        for ($i = 0; $i < $this->codelen; $i++) {
            //文字顏色
            $color = imagecolorallocate($this->img, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156));
            //資源句柄 字體大小 傾斜度 字體長(zhǎng)度  字體高度  字體顏色  字體  具體文本
            imagettftext($this->img, $this->fontsize, mt_rand(-30, 30), $_x * $i + mt_rand(1, 5), $this->height / 1.4, $color, $this->font, $this->code[$i]);
        }
    }

    //隨機(jī)線條
    private function createLine()
    {
        //隨機(jī)線條
        for ($i = 0; $i < 6; $i++) {
            $color = imagecolorallocate($this->img, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156));
            imageline($this->img, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $color);
        }
        //隨機(jī)雪花
        for ($i = 0; $i < 45; $i++) {
            $color = imagecolorallocate($this->img, mt_rand(220, 255), mt_rand(220, 255), mt_rand(220, 255));
            imagestring($this->img, mt_rand(1, 5), mt_rand(0, $this->width), mt_rand(0, $this->height), '*', $color);
        }
    }

    //輸出背景
    private function outPut()
    {
        //生成標(biāo)頭
        header('Content-type:image/png');
        //輸出圖片
        imagepng($this->img);
        //銷毀結(jié)果集
        imagedestroy($this->img);
    }

    //對(duì)外輸出
    public function doimg()
    {
        //加載背景
        $this->createBg();
        //加載文件
        $this->createCode();
        //加載線條
        $this->createLine();
        //加載字體
        $this->createFont();
        //加載背景
        $this->outPut();
    }

    //獲取驗(yàn)證碼
    public function getCode()
    {
        return strtolower($this->code);
    }

    //驗(yàn)證驗(yàn)證碼
    public function checkCode($code, $clear = false)
    {
//        session_start();
        if (Session::get('VerifyCode') == strtolower($code)) {
            if($clear) $this->clearCode();
            return true;
        }
        if($clear) $this->clearCode();
        return false;
    }

    //清除驗(yàn)證碼
    public function clearCode()
    {
        Session::del('VerifyCode');
//        session_start();
//        unset ($_SESSION['VerifyCode']);
    }
}

驗(yàn)證

ob_clean();
$verify = new Code();
$verify->doimg();

這樣即可輸出如下驗(yàn)證碼

PHP制作圖形驗(yàn)證碼

可以調(diào)整參數(shù)控制驗(yàn)證碼的大小,干擾項(xiàng)等。

拓展

接下來(lái)介紹下拓展的功能,怎么加強(qiáng)驗(yàn)證碼的干擾項(xiàng),怎么結(jié)合到項(xiàng)目麗進(jìn)行登錄驗(yàn)證。

1. 加強(qiáng)干擾

首先我們可以看到上面的截圖中少數(shù)線條,如果外者使用分析工具來(lái)解碼,那么會(huì)很簡(jiǎn)單的就解出我們的驗(yàn)證碼,這時(shí)候就需要添加線條的數(shù)量,在代碼中找到以下代碼并修改

//隨機(jī)線條
private function createLine()
{
    //隨機(jī)線條 
    for ($i = 0; $i < 6; $i++) {
        $color = imagecolorallocate($this->img, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156));
        imageline($this->img, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $color);
    }
    //隨機(jī)雪花
    for ($i = 0; $i < 45; $i++) {
        $color = imagecolorallocate($this->img, mt_rand(220, 255), mt_rand(220, 255), mt_rand(220, 255));
        imagestring($this->img, mt_rand(1, 5), mt_rand(0, $this->width), mt_rand(0, $this->height), '*', $color);
    }
}

上面的數(shù)字6可以慢慢調(diào)整,然后查看效果直到滿意。同時(shí)可以看到驗(yàn)證碼中有很多雪花效果,這個(gè)也是干擾項(xiàng),可以修改上面的數(shù)字45來(lái)調(diào)整到自己滿意的結(jié)果。

注意:代碼中的$charset變量,驗(yàn)證碼是從這邊隨機(jī)取字符來(lái)生存驗(yàn)證,由于小寫的i和L展示的效果很難分辨,所以我們?nèi)コ薸字符。

2. 接入項(xiàng)目驗(yàn)證

新建個(gè)文件,代碼如下

doimg();

然后在現(xiàn)有的系統(tǒng)登錄頁(yè)面引入這個(gè)接口即可展示驗(yàn)證碼,在用戶填寫提交之后,服務(wù)端做以下驗(yàn)證

//驗(yàn)證驗(yàn)證碼
public function checkCode($code, $clear = false)
{
    if (Session::get('VerifyCode') == strtolower($code)) {
        if($clear) $this->clearCode();
            return true;
    }
    if($clear) $this->clearCode();
    return false;
}
//清除驗(yàn)證碼
public function clearCode()
{
    Session::del('VerifyCode');
}

以上就是PHP生成圖形驗(yàn)證碼(加強(qiáng)干擾型)的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注創(chuàng)新互聯(lián)其它相關(guān)文章!


本文名稱:PHP制作圖形驗(yàn)證碼
轉(zhuǎn)載來(lái)源:http://www.xueling.net.cn/article/ihoopd.html

其他資訊

在線咨詢
服務(wù)熱線
服務(wù)熱線:028-86922220
TOP
主站蜘蛛池模板: 国产无线乱码一区二三区 | 一区二区三区免费在线观看 | av免费观看大全 | 国产免费丝袜调教视频爱 | 欧洲一级中文字幕在线 | 久久精品无码一区二区小草 | 97爱爱网 | tube8xxxxx中国 | aa日韩免费精品视频一 | 亚洲综合色区另类av | 亚洲视频精品一区二区 | 午夜激情一区二区 | 亚洲成人123 | 99久久国产综合精品女不卡 | 无遮挡裸体免费视频尤物 | 亚洲午夜免费福利视频 | 人人爽亚洲AV人人爽AV人人片 | 成人国产精品入麻豆 | 一级黄免费 | 欧美亚洲日韩国产人成在线播放 | 午夜精品久久久久久久99无限制 | 大JI巴好深好爽又大又粗视频 | 美女在线视频一区二区三区 | 欧美人与动性行为视频 | 国产精品人妻一区二区网站 | 久久伊人成人网 | 色哟哟vip | 欧美日韩综合一区二区在线观看视频 | 亚洲丝袜另类校园欧美 | 国产精品视频免费观看www | 亚洲黄色网络 | 亚洲午夜成人精品无码软件 | 国产乱码精品一区二区三区爽爽爽 | 亚洲精品国产情侣AV在线 | 免费看的一级毛片 | 成人网站色52色在线观看 | 琪琪五月天 | 熟妇女的欲乱在线观看 | 成人精品一区 | 精品一二三区视频 | 国产日韩欧美视频 |