這篇文章主要介紹了PHP驗(yàn)證碼無(wú)法顯示的原因及解決辦法的相關(guān)資料,這里說(shuō)明了如何出現(xiàn)無(wú)法顯示的原因及相應(yīng)的解決辦法,需要的朋友可以參考下
PHP驗(yàn)證碼無(wú)法顯示的原因及解決辦法
一、如果是utf-8,就有可能是BOM沒(méi)有清除
二、在Header("Content-type: image/PNG"); 之前有輸出
三、第一行PHP隱藏了代碼,如空格,回車(chē)等。 解決代碼:
$image_width=70; //設(shè)置圖像寬度 $image_height=18; //設(shè)置圖像高度 $new_number=$_GET[num]; //$new_number=5; $num_image=imagecreate($image_width,$image_height); //創(chuàng)建一個(gè)畫(huà)布 imagecolorallocate($num_image,255,255,255); //設(shè)置畫(huà)布的顏色 $black=imagecolorallocate($num_image,0,0,0); for($i=0;$i<strlen($new_number);$i++){ //循環(huán)讀取SESSION變量中的驗(yàn)證碼 $font=mt_rand(3,5); //設(shè)置隨機(jī)的字體 $x=mt_rand(1,8)+$image_width*$i/4; //設(shè)置隨機(jī)字符所在位置的X坐標(biāo) $y=mt_rand(1,$image_height/4); //設(shè)置隨機(jī)字符所在位置的Y坐標(biāo) $color=imagecolorallocate($num_image,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)); //設(shè)置字符的顏色 imagestring($num_image,$font,$x,$y,$new_number[$i],$color); //水平輸出字符 } header("content-type:image/png"); //設(shè)置創(chuàng)建圖像的格式 imagepng($num_image); //生成PNG格式的圖像 imagedestroy($num_image); //釋放圖像資源
以上就是php中驗(yàn)證碼顯示不出來(lái)的解決辦法的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!