1
回答
关于php验证码的问题

验证码出现乱码如何解决

<?php   
function vcode($width=120,$height=40,$fontSize=30,$countElement=5,$countPixel=100,$countLine=4){
 header('Content-type:image/jpeg');    //请求页面的内容是jpeg格式的图像(这是验证码的图片格式)
 $element=array('a','b','c','d','e','f','g','h','i','j','k','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
 $string='';
 for ($i=0;$i<$countElement;$i++){
  $string.=$element[rand(0,count($element)-1)];
 }
 $img=imagecreatetruecolor($width, $height);
 $colorBg=imagecolorallocate($img,rand(200,255),rand(200,255),rand(200,255));
 $colorBorder=imagecolorallocate($img,rand(200,255),rand(200,255),rand(200,255));
 $colorString=imagecolorallocate($img,rand(10,100),rand(10,100),rand(10,100));
 imagefill($img,0,0,$colorBg);
 for($i=0;$i<$countPixel;$i++){
  imagesetpixel($img,rand(0,$width-1),rand(0,$height-1),imagecolorallocate($img,rand(100,200),rand(100,200),rand(100,200)));
 }
 for($i=0;$i<$countLine;$i++){
  imageline($img,rand(0,$width/2),rand(0,$height),rand($width/2,$width),rand(0,$height),imagecolorallocate($img,rand(100,200),rand(100,200),rand(100,200)));
 }
 //imagestring($img,5,0,0,'abcd',$colorString);
 imagettftext($img,$fontSize,rand(-5,5),rand(5,15),rand(30,35),$colorString,'font/ManyGifts.ttf',$string);
 imagejpeg($img);
 imagedestroy($img);
 return $string;   // 返回imagettftext里的$string
}
?>

输出

<?php   
session_start(); 
include_once 'inc/vcode.inc.php';
$_SESSION['vcode']=vcode(100,40,30,4);
?>

这是无bom格式

乱码:

<br />
<font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: imagettftext(): Invalid font filename in D:\wamp\www\mywork\inc\vcode.inc.php on line <i>21</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0003</td><td bgcolor='#eeeeec' align='right'>132352</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='D:\wamp\www\mywork\show_code.php' bgcolor='#eeeeec'>..\show_code.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0008</td><td bgcolor='#eeeeec' align='right'>147824</td><td bgcolor='#eeeeec'>vcode(  )</td><td title='D:\wamp\www\mywork\show_code.php' bgcolor='#eeeeec'>..\show_code.php<b>:</b>4</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.0039</td><td bgcolor='#eeeeec' align='right'>179752</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.imagettftext' target='_new'>imagettftext</a>
(  )</td><td title='D:\wamp\www\mywork\inc\vcode.inc.php' bgcolor='#eeeeec'>..\vcode.inc.php<b>:</b>21</td></tr>
</table></font>
���JFIF��������>CREATOR: gd-jpeg v1.0 (using IJG JPEG v90), default quality
��C�  � ���		

 $.' ",#(7),01444'9=82<.342��C			

2!!22222222222222222222222222222222222222222222222222���(�d"������������� �	
������}�!1A Qa�"q2亼�#B绷R佯$3br�	
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz儎厗噲墛挀敃枟槞殺¥ウЖ┆渤吹斗腹郝媚牌侨墒矣哉肿刭卺忏溴骁栝犟蝮趱鲼���������� �	
������w�!1 AQ�aq"2�B憽绷	#3R�br�
$4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz們剠唶垑姃摂晼棙櫄ⅲぅΗī炒刀犯购旅呐魄壬室釉罩棕仝忏溴骁栝牝篝貊鼬����?����騶伕舌�跚'螗u寚 0邻H?�妘7粓;裁�8
8�0>�]X癡┟�zg��#螃葐@P�攩�!刽 褶烲�憯!J�r�1魻b€懏�T鐜9'鷵JA�<�F?*`_f菁朷沽跸l錇;斛<�仦���:鄸 鹉t9睨MX�r:渜?J#`闔u槍疦1�?
l�!�鄙�厉�2J蓇懦l徏�:�粸净�:髥磖�2}�&�-犃9~欞�29�9#m圩z3+?嚫�灨#筨1菗�6ゝ蜨99'?仹詐(Kx�#F�嶫裥湡鎖�2翂n@�跨捉�:夾�怬r€ rr���璖鹵驱�?铷盔憾萀娻�d鄡頊g佅字慪慶Y鏽	D8''��隙i裀呶:閣c���L鸘膞虼撄u弡M洸~更{h�U,B€X鍒N1�;愁g�&琤G柺蠮然勤��~�}O杂歖X�-潣�鉹�濭茈忕薤1*2� `c庄5RI銱0S;D亁S袔�9飳s渂孂�+頢歮U甐#�6?w韾Зf1襁t餼揑裕�?>手Y€翴绻U囵>BW帳瀞贼燹%  镧d粔@}熄響�<dy`	<蘾2H噻g4s遜U�*�奈O非n��1酃錴簌g�€���*鈷�	R圊�4釬*aO��t?淹�)ㄔ]橵�;Xf鵑笼纭�瘾�X�'' 源Rn鉐罞R孞�!K3佋�.#笍y
痨�埬� 俉8<s牲J*腏钂F讶绬V腞愛�m寥�9硐鏓#+J� v竐幷s筄�輲p垠<慠Z�$穲琣片*2:=?/J(q_QZ8頢d褌T幥錶uS钳QQ0炚K+塧Q挷2廸锴訯Qbf瑴簱莫睄冰y�类濶q苧M(c竼
 p榥?>窘(ⅷ≡撒虌穝賊G鏖子Q@茄E€
PHP
举报
hobby1120
发帖于2年前 1回/141阅
顶部