PHP验证码无法显示的原因
生活随笔
收集整理的這篇文章主要介紹了
PHP验证码无法显示的原因
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
一、如果是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); //釋放圖像資源轉載于:https://my.oschina.net/lwl1989/blog/514328
總結
以上是生活随笔為你收集整理的PHP验证码无法显示的原因的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【面试必备】Swiftamp;nbsp;
- 下一篇: 基于webpack搭建前端工程解决方案探