php生成驗證碼

2022-07-24 23:18:22 字數 1867 閱讀 7245

<?php

namespace service;

class

verifycode

if($codelength

)

$this->jamimg = $this->resourceroot.$this->jamimg;

$this->font = $this->resourceroot.$this->font;

}/**

* 設定生成驗證碼要用的字元型別

* @param int $chrtype 1 數字,2 大寫字母, 4 小寫字母, 8 中文 混合型別為對應型別之和

*/public

function setchrtype($chrtype

) /**

* 設定驗證碼的長度

* @param int $codelength 驗證碼長度

*/public

function setcodelength($codelength

) /**

* 初始化生成驗證碼將要用到的字符集

*/private

function

initchrs()

if($this->chrtype & 2)

if($this->chrtype & 4)

if($this->chrtype & 8)

}/**

* 新增生成驗證碼要用到的字符集

* @param int $start 字符集起始ascii碼

* @param int $length 字符集長度

*/private

function addascii($start, $length

) /**

* 找出數值對應的中文字元

* @param int $code 數值

*/private

function codetoutf8($code

) /**

* 將隨機生成的數值轉換成對應的字元

* @param int $code 隨機數

* @return string

*/private

function transfercode($code

)else

}if($item[0])

else

}/**

* 生成驗證碼

*/public

function

generatecode()

return

$this->getcode();

}/**

* 給制驗證碼

*/protected

function

createimage()

imagecopy(

$this->img, $jamimg, 0, 0, rand(0,$imageinfo[0]-$this->sizewidth), rand(0,$imageinfo[1]-$this->sizeheight), $this->sizewidth ,$this->sizeheight);

}/**

* 輸出驗證碼

*/protected

function

printimage()

/*** 生成驗證碼

*/public

function

draw()

/*** 獲取本次驗證碼內容

* @return string

*/public

function

getcode()

}?>

public

function

picverifycode()

php生成驗證碼

header content type image gif 初始化 border 0 是否要邊框 1要 0不要 how 4 驗證碼位數 w how 15 寬度 h 20 高度 fontsize 5 字型大小 alpha abcdefghijkmnopqrstuvwxyz 驗證碼內容1 字母 numb...

php 生成驗證碼

驗證碼個數 num 4 驗證碼寬度 width 80 驗證碼高度 height 20 驗證碼 注意是字串 code 生成驗證碼 for i 0 i num i 驗證碼儲存到session中 session start session verifycode code 建立影象 image imagec...

php 生成驗證碼

che.php session start im imagecreatetruecolor 100,30 設定顏色 bg imagecolorallocate im,0,0,0 背景色 te imagecolorallocate im,255,255,255 字型顏色 for i 0 i 4 i 輸...