天天看點

thinkphp 驗證碼

中文驗證碼

英文驗證碼

驗證碼類

    lib->org->util->img.class.php有個驗證碼方法

    即圖像處理類,不是系統中的核心類,不會自動加載

 需要導入一次。

 用import()方法

 import('ORG.Util.Image');注意大小寫

 import('@.ORG.Image');@目前項目的LIB檔案夾

 這是兩種導入方式

第一步,我們需要知道使用者輸入的驗證碼是否正确

驗證碼跨頁面,存在session當中的,并且這個驗證碼是

被md5過的。

if($_SESSION['verify']!=md5($_POST['verify']))

{

$this->error("驗證碼錯誤!");

}

生成驗證碼

public function verify(){

      import("@.ORG.Image");

      Image::buildImageVerify(4,1);

    }

參數解釋:

string buildImageVerify ([string $length = 4], [string $mode = 1], [string $type = 'png'], [string $width = 48], [string $height = 22], [ $verifyName = 'verify'])

第一個參數為長度,預設為4個長度

第二個為模式,

  0字母

  1數字

  2小寫字母

  3為小寫字母

  4為中文

  5混合

第三個為圖像輸出的類型  預設為png

第四個 寬度

第五個 高度 22px

第六個  驗證碼儲存在session中的名稱。

中文驗證碼:

  GBImage();

  加載字型,

  把字型放入到thinkphp/lib/org/util下面。。

  //預設字型是黑體 ,放到Org/Util檔案夾下。

參數:

  length

  type

  height

  fontface

  verifyName 

  //判斷驗證碼

  public function verifyCheck() { 

//防止頁面亂碼 

header('Content-type:text/html;charset=utf-8'); 

if (md5($_POST['verifyTest']) != Session::get('verify')) { 

echo '驗證碼錯誤'; 

else { 

echo '驗證碼正确'; 

}

分頁

  UserAction.class.php

  limit來實作

  1.導入

  import('ORG.Util.Page');

  import(@.Org.Page');

  2.總數

   $count=$uer->count();

   每頁3條

   $page=new Page($count,3);