茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    PHP驗(yàn)證碼類(lèi)實(shí)現(xiàn)驗(yàn)證碼功能
    來(lái)源:易賢網(wǎng) 閱讀:1050 次 日期:2015-04-15 14:42:38
    溫馨提示:易賢網(wǎng)小編為您整理了“PHP驗(yàn)證碼類(lèi)實(shí)現(xiàn)驗(yàn)證碼功能”,方便廣大網(wǎng)友查閱!

    PHP驗(yàn)證碼類(lèi)實(shí)現(xiàn)驗(yàn)證碼功能,有兩個(gè)方法,分別是用內(nèi)置字體和自定義字體生成驗(yàn)證碼。具體代碼如下:

    <?php

    /**

    * 驗(yàn)證碼生成類(lèi)

    * @example

    * $pic = new uImage();

    * $code = $pic->getVerifyCode();

    * header("Content-type:image/png");

    * $pic->captchaFromFont($font='RAVIE.TTF'); or $pic->captcha();

    */

    class uImage {

    /**

    * 驗(yàn)證碼字符

    * @access protected

    */

    protected $code;

    /**

    * 生成圖片驗(yàn)證碼,直接輸出的是圖片,字體大小是內(nèi)置字體,最大是5

    * @access public

    * @param int $width 驗(yàn)證碼圖片寬度

    * @param int $height 驗(yàn)證碼圖片的高度

    * @param int $snow 背景雪花的數(shù)量

    * @param int $line 干擾線的條數(shù)

    */

    public function captcha($width=100, $height=30, $snow=80, $line=3) {

    $pic = imagecreatetruecolor($width, $height);

    $backageColor = imagecolorallocate($pic, 0xFF, 0xFF, 0xFF);

    imagefill($pic, 0, 0, $backageColor);

    //打雪花

    for($i=0; $i<=$snow;$i++) {

    $color = imagecolorallocate($pic, mt_rand(150, 230), mt_rand(150, 230), mt_rand(150, 230));

    imagechar($pic, 1, mt_rand(0, $width), mt_rand(0, $height), "*", $color);

    imagecolordeallocate ($pic, $color);

    }

    //畫(huà)干擾線

    for($i=0; $i<=$line; $i++) {

    $x1 = mt_rand(2, $width * 0.2);

    $x2 = mt_rand($width * 0.8, $width - 2);

    $y1 = mt_rand(2, $height - 2);

    $y2 = mt_rand(2, $height - 2);

    $color = imagecolorallocate($pic, mt_rand(130, 250), mt_rand(130, 250), mt_rand(130, 250));

    imageline($pic, $x1, $y1, $x2, $y2, $color);

    imagecolordeallocate ($pic, $color);

    }

    //畫(huà)字符

    $code = $this->code;

    $eachW = $width / strlen($code); //圖片依據(jù)字符個(gè)數(shù)分配等份數(shù)

    $fontWidth = imagefontwidth(5); //取得字體寬度

    $fontHeight = imagefontheight(5); //取得字體高度

    for($i=0; $i<strlen($code);$i++) {

    $color = imagecolorallocate($pic, mt_rand(30, 155), mt_rand(30, 155), mt_rand(30, 150));

    $x = mt_rand($eachW * $i, $eachW * ($i+1)-$fontWidth);

    $y = mt_rand(3, $height-$fontHeight);

    imagechar($pic, 5, $x, $y, $code{$i}, $color); //水平畫(huà)字符

    imagecolordeallocate ($pic, $color);

    }

    //輸出

    ob_start();

    ob_clean();

    imagepng($pic);

    imagedestroy($pic);

    }

    /**

    * 根據(jù)自定義字體生成驗(yàn)證碼

    * @access public

    * @param string $font 字符文件, TrueType 字體文件,.ttf字體

    * @param int $fontWeight 字符大小

    * @param int $width 圖片寬

    * @param int $height 圖片高

    * @param int $snow 背景雪花個(gè)數(shù)

    * @param int $line 干擾線條數(shù)

    * @param int $padding 圖片內(nèi)邊距

    */

    public function captchaFromFont($font, $fontWeight=16, $width=100, $height=30, $snow=80, $line=3, $padding=3){

    if(!isset($font)){

    return false;

    }

    $pic = imagecreatetruecolor($width, $height);

    $backageColor = imagecolorallocate($pic, 0xFF, 0xFF, 0xFF);

    imagefill($pic, 0, 0, $backageColor);

    imagecolordeallocate ($pic, $backageColor);

    //打雪花

    for($i=0; $i<=$snow;$i++) {

    $color = imagecolorallocate($pic, mt_rand(150, 230), mt_rand(150, 230), mt_rand(150, 230));

    imagechar($pic, 1, mt_rand(0, $width), mt_rand(0, $height), "*", $color);

    imagecolordeallocate ($pic, $color);

    }

    //畫(huà)干擾線

    for($i=0; $i<=$line; $i++) {

    $x1 = mt_rand(2, $width * 0.2);

    $x2 = mt_rand($width * 0.8, $width - 2);

    $y1 = mt_rand(2, $height - 2);

    $y2 = mt_rand(2, $height - 2);

    $color = imagecolorallocate($pic, mt_rand(130, 250), mt_rand(130, 250), mt_rand(130, 250));

    imageline($pic, $x1, $y1, $x2, $y2, $color);

    imagecolordeallocate ($pic, $color);

    }

    //畫(huà)字符

    $code = $this->code;

    $eachW = $width / strlen($code); //圖片依據(jù)字符個(gè)數(shù)分配等份數(shù)

    $codeArray = str_split($code);

    for($i=0; $i<count($codeArray); $i++){

    //取得字符寬高

    $fontbox = imagettfbbox($fontWeight, 0, $font, $codeArray[$i]);

    $fontWidth = $fontbox[2] - $fontbox[0];

    $fontHeight = $fontbox[1] - $fontbox[7];

    $color = imagecolorallocate($pic, mt_rand(30, 155), mt_rand(30, 155), mt_rand(30, 150)); //字符顏色

    $angle = mt_rand(-20, 20); //字符角度

    if($i==0){

    $start = $eachW * $i+$padding;

    $end = $eachW * ($i+1)-$fontWidth;

    }

    elseif($i == count($codeArray)){

    $start = $eachW * $i;

    $end = $eachW * ($i+1)-$fontWidth-$padding;

    }

    else{

    $start = $eachW * $i;

    $end = $eachW * ($i+1)-$fontWidth-$padding;

    }

    $x = $start < $end ? mt_rand($start, $end) : $start;

    $y = ($fontHeight+$padding) > $height ? $padding : mt_rand($fontHeight+$padding, $height-$padding);

    imagettftext($pic, $fontWeight, $angle, $x, $y, $color, $font, $codeArray[$i]); //用 TrueType 字體向圖像寫(xiě)入文本

    imagecolordeallocate ($pic, $color);

    }

    //輸出

    ob_start();

    ob_clean();

    imagepng($pic);

    imagedestroy($pic);

    }

    /**

    * 獲取驗(yàn)證碼

    * @access public

    * @param int $len 驗(yàn)證碼字符的長(zhǎng)度

    * @return strint 生成的驗(yàn)證碼字符

    */

    public function getVerifyCode($len=4){

    if(!isset($this->code)){

    $this->code = $this->getCode($len);

    }

    return $this->code;

    }

    /**

    * 生成驗(yàn)證碼

    * @access protected

    * @param int $len 驗(yàn)證碼字符的長(zhǎng)度

    * @return strint 生成的驗(yàn)證碼字符

    */

    protected function getCode($len) {

    $str = "23456789abcdefghijklmnqrstuvwxyz";

    $code = "";

    for($i=0; $i<$len; $i++) {

    $code .= $str{mt_rand(0, strlen($str)-1)};

    }

    $this->code = $code;

    return $code;

    }

    }

    更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

    更多信息請(qǐng)查看CMS教程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:PHP驗(yàn)證碼類(lèi)實(shí)現(xiàn)驗(yàn)證碼功能
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!
    相關(guān)閱讀CMS教程

    2026上岸·考公考編培訓(xùn)報(bào)班

    • 報(bào)班類(lèi)型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專(zhuān)用圖標(biāo)
    聯(lián)系電話(huà):0871-65099533/13759567129 獲取招聘考試信息及咨詢(xún)關(guān)注公眾號(hào):hfpxwx
    咨詢(xún)QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)