php中驗證碼顯示不出來的解決辦法

來源:互聯網
上載者:User
這篇文章主要介紹了PHP驗證碼無法顯示的原因及解決辦法的相關資料,這裡說明了如何出現無法顯示的原因及相應的解決辦法,需要的朋友可以參考下

PHP驗證碼無法顯示的原因及解決辦法

一、如果是utf-8,就有可能是BOM沒有清除

二、在Header("Content-type: image/PNG"); 之前有輸出

三、第一行PHP隱藏了代碼,如空格,斷行符號等。 解決代碼:


$image_width=70;           //設定映像寬度$image_height=18;       //設定映像高度$new_number=$_GET[num];//$new_number=5;$num_image=imagecreate($image_width,$image_height); //建立一個畫布imagecolorallocate($num_image,255,255,255);    //設定畫布的顏色$black=imagecolorallocate($num_image,0,0,0);/**/for($i=0;$i<strlen($new_number);$i++){ //迴圈讀取SESSION變數中的驗證碼  $font=mt_rand(3,5);               //設定隨機的字型  $x=mt_rand(1,8)+$image_width*$i/4;        //設定隨機字元所在位置的X座標  $y=mt_rand(1,$image_height/4);          //設定隨機字元所在位置的Y座標  $color=imagecolorallocate($num_image,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200));  //設定字元的顏色  imagestring($num_image,$font,$x,$y,$new_number[$i],$color);     //水平輸出字元}header("content-type:image/png");   //設定建立映像的格式imagepng($num_image);     //產生PNG格式的映像imagedestroy($num_image);   //釋放映像資源

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.