<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                >[success] ### 第四難 VerificationCode驗證碼 * 驗證碼可以防止機器人的惡意請求(惡意表單提交、破解密碼、刷票、論壇灌水......) * 案例鏈接:https://pan.baidu.com/s/1kVcOTuv 密碼:d6j9 ![](https://box.kancloud.cn/98570d04717f59331b20808fd201df5f_475x153.png) >[success] ### 例子2 * 字體文件下載msjh.ttf 鏈接:https://pan.baidu.com/s/1jHLpYku 密碼:el2k ~~~php <?php class VerificationCode { private $charset = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789"; //隨機因子 public $code; //驗證碼 private $codelen = 4; //驗證碼長度 private $width = 130; //寬度 private $height = 50; //高度 private $img; //圖像資源句柄 private $font; //制定字體 private $fontSize = 20; //字體大小 private $fontColor; //字體顏色 public function __construct() { //制定字體 $this->font = 'msjh.ttf';//注意字體路徑要寫對,否則顯示不了圖片 } //生成驗證碼 private function createCode() { $len = strlen($this->charset) - 1; for ($i = 0; $i < $this->codelen; $i++) { $this->code .= $this->charset[mt_rand(0, $len)]; } } //生成背景 private function createBg() { $this->img = imagecreatetruecolor($this->width, $this->height); //imagecreatetruecolor — 新建一個真彩色圖像 $color = imagecolorallocate($this->img, mt_rand(157, 255), mt_rand(157, 255), mt_rand(157, 255)); //imagecolorallocate — 為一幅圖像分配顏色 imagefilledrectangle($this->img, 0, $this->height, $this->width, 0, $color); } //生成文字 private function createFont() { //每個字符的平均寬度 $x = $this->width / $this->codelen; for ($i = 0; $i < $this->codelen; $i++) { //字體的顏色 $this->fontColor = imagecolorallocate($this->img, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156)); imagettftext($this->img, $this->fontSize, mt_rand(-10, 10), $i * $x + mt_rand(1, 3), $this->height / 1.3, $this->fontColor, $this->font, $this->code[$i]); //imagestring($this->img,5,$i*$x+mt_rand(1,5),5,$this->code[$i],$this->fontColor); } } //生成線條、雪花 private function createDisturb() { for ($i = 0; $i < 6; $i++) { $color = imagecolorallocate($this->img, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156)); imageline($this->img, mt_rand(0, $this->width), mt_rand(0, $this->width), mt_rand(0, $this->width), mt_rand(0, $this->width), $color); //imageline() 用 color 顏色在圖像 image 中從坐標 x1,y1 到 x2,y2(圖像左上角為 0, 0)畫一條線段。 } for ($i = 0; $i < 100; $i++) { $color = imagecolorallocate($this->img, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)); imagestring($this->img, mt_rand(1, 5), mt_rand(0, $this->width), mt_rand(0, $this->height), '*', $color); //imagestring — 水平地畫一行字符串 } } //輸出 private function outPut() { header("Content-Type:image/png"); imagepng($this->img); imagedestroy($this->img); } //顯示驗證碼 public function showCode() { $this->createBg(); echo $this->code; $this->createCode(); //$_SESSION['code'] = $this->getCode(); $this->createDisturb(); $this->createFont(); $this->outPut(); } //獲取驗證碼 public function getCode() { return strtolower($this->code); } } $code = new VerificationCode(); $code->showCode(); ~~~ ![](https://box.kancloud.cn/b193e6c8c13cb5688764bd0249c0159e_460x195.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看