中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

PHP生成自定義驗(yàn)證碼

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線(xiàn)!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
<?php
public function captcha(){
    $font_dir   = $_SERVER ["DOCUMENT_ROOT"] . "your_ttf_file.ttf"; // 字體庫(kù)
    $img_w      = 58;   // 設(shè)置圖片寬
    $img_h      = 20;   // 設(shè)置圖片高
    $font_size  = 11;   // 字體大小
    $angle_l    = -10;  // 左偏角
    $angle_r    = 10;   // 右偏角
    $code_str   = "ABCDEFGHJKLMNPQRSTUVWXYZ36";
    $word_len   = 4;    // 驗(yàn)證碼位數(shù)
    $padding    = 5;    // 每?jī)蓚(gè)文字之間間隔
    $margin     = 2;    // 左側(cè)邊距
    $base_line  = 15;   // 文字基線(xiàn)位置
    $base_line_offset = 2;  // 基準(zhǔn)線(xiàn)偏移量
    $pixel_num  = 3;    // 雜點(diǎn)數(shù)目基數(shù)
    $pixel_color= 8;    // 雜點(diǎn)只有 $pixel_color 種顏色  總的雜點(diǎn)數(shù)為$pixel_num*$pixel_color
    $noise_font_size = 1; // 雜點(diǎn)字體大小
    $session_key= "my_captcha"; //自定義session鍵名

    header("Cache-Control: no-cache, must-revalidate");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Pragma: no-cache");
    header("Cache-control: private");
    header('Content-Type: image/png');

    session_start();
    $word = "";
    $code_str_len = strlen($code_str) - 1;
    for ($i = 0; $i < $word_len; $i++) {
        $word.= $code_str[rand(0, $code_str_len)];
    }
    $_SESSION [$session_key] = strtolower($word);
    $image = imagecreatetruecolor($img_w, $img_h);
    imagefilledrectangle($image, 0, 0, $img_w - 1, $img_h - 1, imagecolorallocate($image, mt_rand(235, 255), mt_rand(235, 255), mt_rand(235, 255)));

    //繪制雜點(diǎn)
    for($i = 0; $i < $pixel_color; $i++){ 
        $noise_color = imagecolorallocate( $image, mt_rand(150,225), mt_rand(150,225), mt_rand(150,225) );
        for($j = 0; $j < $pixel_num; $j++) {
            imagestring( $image,  $noise_font_size, mt_rand(-10, $img_w), mt_rand(-10, $img_h), $code_str[mt_rand(0, $code_str_len)], $noise_color );
        }
    }

    //繪制文字
    for ($i = 0; $i < $word_len; ++$i) {           
        $color = imagecolorallocate($image, mt_rand(0, 100), mt_rand(20, 120), mt_rand(50, 150));
        imagettftext($image, $font_size, mt_rand($angle_l, $angle_r), $margin, mt_rand($base_line-$base_line_offset, $base_line+$base_line_offset), $color, $font_dir, mb_substr($word, $i, 1, 'utf-8'));
        $margin += (imagefontwidth($font_size) + $padding);
    }

    imagepng($image);
    imagedestroy($image);
    exit;
}

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:通過(guò)JDBC對(duì)MySql進(jìn)行增/刪/改/查操作

下一篇:js實(shí)現(xiàn)返回頁(yè)面頂部功能