久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

CodeIgniter框架驗(yàn)證碼類(lèi)庫(kù)文件與用法示例

這篇文章主要介紹了CodeIgniter框架驗(yàn)證碼類(lèi)庫(kù)文件與用法,結(jié)合實(shí)例形式分析了CodeIgniter框架驗(yàn)證碼類(lèi)庫(kù)文件的定義與具體使用方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了CodeIgniter框架驗(yàn)證碼類(lèi)庫(kù)文件與用法。分享給大家供大家參考,具體如下:

折騰了我四五個(gè)小時(shí),終于,ci的驗(yàn)證碼類(lèi)庫(kù)成功的整出來(lái)了。

下面請(qǐng)看源碼:

在application/libraries建立Authcode.php文件,代碼如下:

<?php
class Authcode
{
 var $CI;
 var $fontPath;//字體路徑
 var $image;
 var $charLen   = 4; //生成幾位驗(yàn)證碼
 var $arrChr   = array();//驗(yàn)證碼字符
 var $width    = 83; //圖片寬
 var $height   = 24; //圖片高
 var $bgcolor   = "#ffffff"; //背景色
 var $showNoisePix  = true; //生成雜點(diǎn)
 var $noiseNumPix  = 80; //生成雜點(diǎn)數(shù)量
 var $showNoiseLine  = true; //生成雜線
 var $noiseNumLine  = 2; //生成雜線數(shù)量
 var $showBorder  = true; //邊框,當(dāng)雜點(diǎn)、線一起作用的時(shí)候,邊框容易受干擾
 var $borderColor  = "#000000";
 function Authcode()
 {
  $this->CI = & get_instance();
  $this->fontPath = realpath(dirname(__FILE__) . '/fonts/'); //字體文件
  //$this->arrChr   = array_merge(range(1, 9) , range('A', 'Z'));//數(shù)字字母驗(yàn)證碼
  //$this->arrChr   = range('A', 'Z');//純字母驗(yàn)證碼
  $this->arrChr = range(0, 9);//純數(shù)字驗(yàn)證碼
 }
 /**
  * 顯示驗(yàn)證碼
  *
  */
 function show()
 {
  $this->image = imageCreate($this->width, $this->height);
  $this->back = $this->getColor($this->bgcolor);
  imageFilledRectangle($this->image, 0, 0, $this->width, $this->height, $this->back);
  $size = $this->width / $this->charLen - 4;
  if ($size > $this->height) {
   $size = $this->height;
  }
  $left = ($this->width - $this->charLen * ($size + $size / 10)) / $size + 5;
  $code = '';
  for($i = 0; $i < $this->charLen; $i ++) {
   $randKey = rand(0, count($this->arrChr) - 1);
   $randText = $this->arrChr[$randKey];
   $code .= $randText;
   $textColor = imageColorAllocate($this->image, rand(0, 100), rand(0, 100), rand(0, 100));
   $font = $this->fontPath . '/' . rand(1, 5) . ".ttf";
   $randsize = rand($size - $size / 10, $size + $size / 10);
   $location = $left + ($i * $size + $size / 10);
   @imagettftext($this->image, $randsize, rand(- 18, 18), $location, rand($size - $size / 10, $size + $size / 10) + 2, $textColor, $font, $randText);
  }
  if ($this->showNoisePix == true) {
   $this->setNoisePix();
  }
  if ($this->showNoiseLine == true) {
   $this->setNoiseLine();
  }
  if ($this->showBorder == true) {
   $this->borderColor = $this->getColor($this->borderColor);
   imageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $this->borderColor);
  }
  $this->CI->session->set_userdata('auth_code', $code);
  ob_clean();
  header("Content-type: image/jpeg");
  imagejpeg($this->image);
  imagedestroy($this->image);
 }
 /**
  * 顯示驗(yàn)證碼的JS調(diào)用
  *
  */
 function showscript()
 {
  //顯示驗(yàn)證碼
  echo "var img_src = '/imgauthcode/show/?';\n";
  echo "document.writeln('<img id=\"img_authcode\" src=\"' + img_src + Math.random() + '\" style=\"cursor:hand;\" onclick=\"this.src=img_src + Math.random();\" alt=\"點(diǎn)擊更換圖片\">');";
 }
 /**
  * 檢查驗(yàn)證碼是否正確
  *
  * @param string $auth_code
  * @return bool
  */
 function check($auth_code = null)
 {
  return ($this->CI->session->userdata('auth_code') && $auth_code) ? ($this->CI->session->userdata('auth_code') === $auth_code) : false;
 }
 function getColor($color)
 {
  $color = eregi_replace("^#", "", $color);
  $r = $color[0] . $color[1];
  $r = hexdec($r);
  $b = $color[2] . $color[3];
  $b = hexdec($b);
  $g = $color[4] . $color[5];
  $g = hexdec($g);
  $color = imagecolorallocate($this->image, $r, $b, $g);
  return $color;
 }
 function setNoisePix()
 {
  for($i = 0; $i < $this->noiseNumPix; $i ++) {
   $randColor = imageColorAllocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255));
   imageSetPixel($this->image, rand(0, $this->width), rand(0, $this->height), $randColor);
  }
 }
 function setNoiseLine()
 {
  for($i = 0; $i < $this->noiseNumLine; $i ++) {
   $randColor = imageColorAllocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255));
   imageline($this->image, rand(1, $this->width), rand(1, $this->height), rand(1, $this->width), rand(1, $this->height), $randColor);
  }
 }
}

Authcode.php代碼結(jié)束

在Controller中,有個(gè)admin類(lèi),其中有兩個(gè)方法:

Class Admin extends CI_Controller{
 function __construct()
 {
  parent::__construct();
  $this->load->library('Authcode');
 }
function captcha(){
  if($_POST){
    if ($this->authcode->check($this->input->post('gd_pic'))) {
    echo "right";
   } else {
    echo '驗(yàn)證碼不正確,請(qǐng)重新輸入';
   }
  }else{
   $this->load->view('demo');
  }
 }
 function show_captcha(){ //此方法用于顯示驗(yàn)證碼圖片,歸一個(gè)view中的img的src調(diào)用
  $this->authcode->show();
 }
}

【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過(guò)測(cè)試外,其他素材未做測(cè)試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請(qǐng)勿用于商業(yè)用途。如損害你的權(quán)益請(qǐng)聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。

相關(guān)文檔推薦

我們?cè)谟胮bootcms網(wǎng)站時(shí)候,后臺(tái)驗(yàn)證碼不顯示或者顯示不清楚,這個(gè)要怎么解決? 今天html5模板網(wǎng)就給大家列出一下幾個(gè)會(huì)造成pbootcms驗(yàn)證碼不顯示的原因。 1、中文路徑問(wèn)題(建站大忌
這篇文章主要介紹了CI框架(CodeIgniter)操作redis的方法,結(jié)合實(shí)例形式詳細(xì)分析了CodeIgniter框架針對(duì)redis數(shù)據(jù)庫(kù)操作的相關(guān)配置與使用技巧,需要的朋友可以參考下
這篇文章主要介紹了詳解Yaf框架PHPUnit集成測(cè)試方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
這篇文章主要介紹了Laravel5.2使用Captcha生成驗(yàn)證碼(session巨坑),需要的朋友可以參考下
這篇文章主要介紹了thinkPHP5框架數(shù)據(jù)庫(kù)連貫操作之cache()用法,結(jié)合實(shí)例形式分析了thinkPHP5中緩存cache的應(yīng)用場(chǎng)景及連貫操作中cache的設(shè)置、更新、刪除等操作技巧,需要的朋友可以參考下
這篇文章主要介紹了Laravel框架+Blob實(shí)現(xiàn)的多圖上傳功能,結(jié)合實(shí)例形式詳細(xì)分析了Laravel框架+Blob進(jìn)行多張圖片上傳操作的前端提交與后臺(tái)處理相關(guān)操作技巧,需要的朋友可以參考下
主站蜘蛛池模板: av在线影院 | 中文字幕在线观看 | 亚州无限乱码 | 欧美性生交大片免费 | 天天曰天天曰 | 天天操夜夜操 | 欧美一区二区三区久久精品 | a黄视频 | 久久精品二区亚洲w码 | 亚洲网站在线播放 | www.国产日本 | 97国产精品视频人人做人人爱 | 人人干人人看 | 日韩欧美三区 | 国产一区二区三区精品久久久 | 在线一区二区三区 | h视频在线看 | 久久美女网 | 中文字幕一区二区三区精彩视频 | 自拍偷拍精品 | 一区在线播放 | 在线欧美日韩 | 日韩在线免费视频 | 精品一二三区 | 日韩欧美三级 | 中文字幕一区二区三区四区 | 午夜爽爽爽男女免费观看 | 欧美一级片在线 | 一级免费在线视频 | 三级在线视频 | 一区不卡在线观看 | 羞羞视频网站免费观看 | 精品国产一区二区三区日日嗨 | 亚洲欧美在线免费观看 | 福利视频一区二区 | 日本久久黄色 | 欧美精品久久 | 天堂在线1| 九色在线 | 操夜夜| 亚洲国产成人av |