如圖,我在image.func.php中輸出getCaptcha();是能夠正常顯示驗證碼的但是,我在新建的getCaptcha.php中調(diào)用image.func.php再使用getCaptcha()的時候卻報錯了,這是為什么??image.func.php中的代碼:<?php
????function?getCaptcha($type?=?3,$length?=?4,$pixel?=?30,$line?=?0){
session_start();
????//創(chuàng)建底圖
????$width?=?80;
????$height?=?30;
????$image?=?imagecreatetruecolor($width,?$height);
????$white?=?imagecolorallocate($image,?255,?255,?255);
????$black?=?imagecolorallocate($image,?0,?0,?0);
????//填充畫布
????//imagefilledrectangle($image,?1,?1,?$width-2,?$height-2,?$white);
????imagefill($image,?0,?0,?$white);
????
????//獲取驗證碼字段,儲存在session中
????$type?=?3;
????$length?=?4;
????$chars?=?buildRandomString($type,$length);
????$sess_name?=?"captcha";
????$_SESSION[$sess_name]?=?$chars;
????$fontfiles?=?array("arial.ttf","ariblk.ttf","simkai.ttf","SIMLI.TTF","simsun.ttc","STLITI.TTF");
????for?($i=0;?$i?<?$length;?$i++)?{?
???? $fontsize?=?mt_rand(12,18);
???? $angle?=?mt_rand(-15,15);
???? $x?=?($i*15)?+?mt_rand(2,5);
???? $y?=?mt_rand(15,25);
???? $color?=?imagecolorallocate($image,?mt_rand(50,150),?mt_rand(50,150),?mt_rand(50,150));
???? $font?=?"../fonts/"?.?$fontfiles[mt_rand(0,count($fontfiles)-1)];
???? $text?=?substr($chars,?$i,?1);
???? imagettftext($image,?$fontsize,?$angle,?$x,?$y,?$color,?$font,?$text);
????
????}
????
????//創(chuàng)建干擾元素
????if($pixel){
????for?($i=0;?$i?<?$pixel;?$i++)?{?
???? $jamColor?=?imagecolorallocate($image,?mt_rand(100,220),?mt_rand(100,220),?mt_rand(100,220));
???? imagesetpixel($image,?mt_rand(0,$width-1),?mt_rand(0,$height-1),?$jamColor);
????}
}
if($line){
for?($i=0;?$i?<?$line;?$i++)?{?
$jamColor?=?imagecolorallocate($image,?mt_rand(100,220),?mt_rand(100,220),?mt_rand(100,220));
imageline($image,?mt_rand(0,$width-1),?mt_rand(0,$height-1),?mt_rand(0,$width-1),?mt_rand(0,$height-1),?$jamColor);
}
}
ob_clean();
header('content-type:image/png');
imagepng($image);
imagedestroy($image);
}
getCaptcha();getCaptcha.php的代碼:<?php
????require_once?'lib/image.func.php';
????getCaptcha();
3 回答

我是新手_請多指教
TA貢獻(xiàn)140條經(jīng)驗 獲得超79個贊
imagettftext中的$font參數(shù)無效,?也就是$font?=?"../fonts/"?.?$fontfiles[mt_rand(0,count($fontfiles)-1)]得到的結(jié)果無效。你新文件中有沒建個文件夾放相對應(yīng)字體的文件"arial.ttf","ariblk.ttf","simkai.ttf","SIMLI.TTF","simsun.ttc","STLITI.TTF"這些
- 3 回答
- 0 關(guān)注
- 1339 瀏覽
添加回答
舉報
0/150
提交
取消