最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Laravel下生成驗證碼的類

 更新時間:2017年11月15日 15:19:08   投稿:lijiao  
這篇文章主要為大家詳細介紹了Laravel下生成驗證碼的類,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Laravel生成驗證碼的類,供大家參考,具體內(nèi)容如下

<?php
 
namespace App\Tool\Validate;
 
//驗證碼類
class ValidateCode {
  private $charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789';//隨機因子
  private $code;//驗證碼
  private $codelen = 4;//驗證碼長度
  private $width = 130;//寬度
  private $height = 50;//高度
  private $img;//圖形資源句柄
  private $font;//指定的字體
  private $fontsize = 20;//指定字體大小
  private $fontcolor;//指定字體顏色
 
  //構(gòu)造方法初始化
  public function __construct()
  {
    $this->font = public_path() . '/fonts/Elephant.ttf';//注意字體路徑要寫對,否則顯示不了圖片
    $this->createCode();
  }
  //生成隨機碼
  private function createCode()
  {
    $_len = strlen($this->charset) - 1;
    for ($i = 0;$i < $this->codelen;++$i) {
      $this->code .= $this->charset[mt_rand(0, $_len)];
    }
  }
  //生成背景
  private function createBg()
  {
    $this->img = imagecreatetruecolor($this->width, $this->height);
    $color = imagecolorallocate($this->img, mt_rand(157, 255), mt_rand(157, 255), mt_rand(157, 255));
    imagefilledrectangle($this->img, 0, $this->height, $this->width, 0, $color);
  }
  //生成文字
  private function createFont()
  {
    $_x = $this->width / $this->codelen;
    for ($i = 0;$i < $this->codelen;++$i) {
      $this->fontcolor = imagecolorallocate($this->img, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156));
      imagettftext($this->img, $this->fontsize, mt_rand(-30, 30), $_x * $i + mt_rand(1, 5), $this->height / 1.4, $this->fontcolor, $this->font, $this->code[$i]);
    }
  }
  //生成線條、雪花
  private function createLine()
  {
    //線條
    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);
    }
    //雪花
    for ($i = 0;$i < 100;++$i) {
      $color = imagecolorallocate($this->img, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255));
      imagestring($this->img, mt_rand(1, 5), mt_rand(0, $this->width), mt_rand(0, $this->height), '*', $color);
    }
  }
  //輸出
  private function outPut()
  {
    header('Content-type:image/png');
    imagepng($this->img);
    imagedestroy($this->img);
  }
  //對外生成
  public function doimg()
  {
    $this->createBg();
    $this->createLine();
    $this->createFont();
    $this->outPut();
  }
  //獲取驗證碼
  public function getCode()
  {
    return strtolower($this->code);
  }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家?! ?/p>

相關文章

  • smarty模板引擎之配置文件數(shù)據(jù)和保留數(shù)據(jù)

    smarty模板引擎之配置文件數(shù)據(jù)和保留數(shù)據(jù)

    這篇文章主要介紹了smarty模板引擎之配置文件數(shù)據(jù)和保留數(shù)據(jù)的方法,實例分析了smarty模板引擎配置文件數(shù)據(jù)及獲取數(shù)據(jù)的具體技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-03-03
  • destoon官方標簽大全

    destoon官方標簽大全

    這篇文章主要介紹了destoon的標簽,需要的朋友可以參考下
    2014-06-06
  • 詳解PHP數(shù)據(jù)壓縮、加解密(pack, unpack)

    詳解PHP數(shù)據(jù)壓縮、加解密(pack, unpack)

    網(wǎng)絡通信、文件存儲中經(jīng)常需要交換數(shù)據(jù),為了減少網(wǎng)絡通信流量、文件存儲大小以及加密通信規(guī)則,本文介紹了PHP數(shù)據(jù)壓縮、加解密,有興趣的可以了解一下。
    2016-12-12
  • ThinkPHP框架表單驗證操作方法

    ThinkPHP框架表單驗證操作方法

    這篇文章主要介紹了ThinkPHP框架表單驗證操作方法,需要的朋友可以參考下
    2017-07-07
  • phpMyAdmin安裝并配置允許空密碼登錄

    phpMyAdmin安裝并配置允許空密碼登錄

    這篇文章主要介紹了phpMyAdmin安裝并配置允許空密碼登錄,本文適合在開發(fā)環(huán)境中使用,可以快速的部署phpMyAdmin工具,需要的朋友可以參考下
    2015-07-07
  • php 類自動載入的方法

    php 類自動載入的方法

    在PHP5之前,各個PHP框架如果要實現(xiàn)類的自動加載,一般都是按照某種約定自己實現(xiàn)一個遍歷目錄,自動加載所有符合約定規(guī)則的文件的類或函數(shù)。 當然,PHP5之前對面向?qū)ο蟮闹С植⒉皇翘?,類的使用也沒有現(xiàn)在頻繁。 我們來詳細探討下吧。
    2015-06-06
  • thinkPHP中volist標簽用法示例

    thinkPHP中volist標簽用法示例

    這篇文章主要介紹了thinkPHP中volist標簽用法,結(jié)合實例形式分析了thinkPHP中volist標簽的功能、屬性及相關使用技巧,需要的朋友可以參考下
    2016-12-12
  • ThinkPHP之R方法實例詳解

    ThinkPHP之R方法實例詳解

    這篇文章主要介紹了ThinkPHP的R方法,需要的朋友可以參考下
    2014-06-06
  • PHP在線書簽系統(tǒng)分享

    PHP在線書簽系統(tǒng)分享

    這篇文章主要為大家介紹了PHP在線書簽系統(tǒng),分析系統(tǒng)需求、提出解決方案,建立數(shù)據(jù)庫,實現(xiàn)基本網(wǎng)站的框架,需要的朋友可以參考下
    2016-01-01
  • php獲取數(shù)據(jù)庫中數(shù)據(jù)的實現(xiàn)方法

    php獲取數(shù)據(jù)庫中數(shù)據(jù)的實現(xiàn)方法

    下面小編就為大家?guī)硪黄猵hp獲取數(shù)據(jù)庫中數(shù)據(jù)的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06

最新評論

静宁县| 南木林县| 老河口市| 阿克| 保山市| 朝阳县| 永宁县| 台东县| 青神县| 桦川县| 旬阳县| 铜梁县| 柞水县| 铁岭市| 小金县| 岫岩| 南阳市| 县级市| 阿荣旗| 大连市| 家居| 浦城县| 太和县| 武夷山市| 壤塘县| 卓尼县| 海淀区| 宁国市| 新绛县| 阜城县| 紫阳县| 岳阳县| 射阳县| 孝义市| 大姚县| 鲁山县| 柯坪县| 高邑县| 乌鲁木齐市| 图木舒克市| 温宿县|