PHP之驗證碼

來源:互聯網
上載者:User

標籤:寬高   pre   locate   des   填充   div   畫像   ++   code   

 1 <?php 2  3     header("content-type:image/jpeg"); 4     //驗證碼函數 5     function getVerify($type = 4){ 6  7         //字碼錶 8         $chars = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"; 9         //字串的長度10         $len = strlen($chars);11         //預定義code12         $verify = ‘‘;13 14         //產生四位隨機數 ,從字碼錶當中15         for ($i=1; $i <= $type ; $i++) { 16             $one_index = mt_rand(0 ,$len-1);17 18             $verify.= $chars[$one_index];19         }20 21         //建立畫布22         $width = 500;23         $height = 300;24 25         $image = imagecreatetruecolor($width, $height);26 27         //配色28         $color = "";29 30         //隨機顏色31         $color = imagecolorallocate($image,210,105,30); 32         33         34         //填充35         imagefill($image, 0, 0, $color);36         37         38 39         $font = 5;40         //獲得映像的寬高41         $img_w = imagesx($image);42         $img_h = imagesy($image);43 44         //獲得字型的寬高45         $font_w = imagefontwidth($font);46         $font_h = imagefontheight($font);47 48         //獲得字串的寬高49         $str_w = $font_w*$type;50         $str_h = $font_h;51 52         //置中顯示53         $x = ($img_w - $str_w)/2;54         $y = ($img_h - $str_h)/2;55         $color = imagecolorallocate($image, 128,0,0);56         imagestring($image, $font, $x, $y, $verify, $color);57 58         //輸出59         imagejpeg($image);60 61         //銷毀畫像資源62         imagedestroy($image);63     }64 65     getVerify(10);

 

PHP之驗證碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.