linux下php5 安装了php5-gd,但是验证码图片还是不能显示求解为何?
图片显示为这样
img.php
- PHP code
<?phpsession_start();$width=50;$height=20;header("Content-type:image/gif");$randval=randStr(4);$im=imagecreatetruecolor($width,$height);$r=array(255,215,235,195,175);$g=array(255,215,235,195,175);$b=array(255,215,235,195,175);$key=rand(0,4);$backColor=imagecolorallocate($im,$r[$key],$g[$key],$b[$key]);$pointColor=imagecolorallocate($im,255,170,255);imagefill($im,0,0,$backColor);$stringColor=imagecolorallocate($im,0,0,0);for($i=0;$i<=100;$i++){ $pointX=rand(2,$width-2); $pointY=rand(2,$height-2); imagesetpixel($im,$pointX,$pointY,$pointColor);}imagestring($im,3,5,1,$randval,$stringColor);$ImageFun='Imagegif';$ImageFun($im);imagedestroy($im);function randStr($len=10){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $string=""; while(strlen($string)<$len){ $string.=substr($char,(rand()%strlen($chars)),1); } return $string;}$_SESSION['identifying']=$randval;?>
- PHP code
?<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE>登录</TITLE><META http-equiv=Content-Type content="text/html; charset=utf-8"><LINK href="images/public.css" type=text/css rel=stylesheet><LINK href="images/login.css" type=text/css rel=stylesheet><STYLE type=text/css></STYLE><META content="MSHTML 6.00.2900.5848" name=GENERATOR><script language='javascript'>function check(){ if(docnument.getElementByID("txtUserName").value==''){ alert("用户名不允许为空"); docnument.getElementById("txtUserName").focus(); return false; } if(docnument.getElementById("txtUserPassword").value==''){ alert("密码不能为空"); docnument.getElementById("txtUserPassword").focus(); return false; } return true;}</script></HEAD><BODY> <form name="loginfrom" action="php/userController.php?flag=login"method="POST"><DIV id=div1> <TABLE id=login height="100%" cellSpacing=0 cellPadding=0 width=800 align=center> <TBODY> <TR id=main> <TD> <TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%"> <TBODY> <TR> <TD colSpan=5> </TD> <TR height=30> <TD width=380> </TD> <TD> </TD> <TD> </TD> <TD> </TD> <TD> </TD> </TR> </TR> <TR height=20> <TD width> </TD> <TD><font size="3"><b>登录<b></font></TD> <td> <input type="radio" name="account" value="student"checked>学生 <input type="radio" name="account" value="teacher">教师 <td></TR> </TR><TR height=20> <TR height=40> <TD rowSpan=4> </TD> <TD>用户名:</TD> <TD> <INPUT class=textbox id="user_name" name="user_name"> </TD> <TD width=120> </TD> </TR> <TR height=40> <TD>密 码:</TD> <TD><INPUT class=textbox id="user_password" type="user_password" name=txtUserPassword> </TD> <TD width=120> </TD> </TR> <TR height=40> <TD>验证码:</TD> <TD vAlign=center colSpan=2> <INPUT id="identifying" size="4" name="identifying"> <img src="img.php"/> <A id=LinkButton1 href="#">不清楚,再来一张</A></TD> </TR> <TR height=40> <TD></TD> <TD align=right> <INPUT id="submit" type="submit" value=" 登 录 " name="submit" onclick="return check()"> </TD> <TD width=120> </TD> </TR> <TR height=110> <TD colSpan=4> </TD> </TR> </TBODY> </TABLE> </TD> </TR> <TR id=root height=104> <TD> </TD> </TR> </TBODY> </TABLE></DIV><DIV id=div2 style="DISPLAY: none"></DIV></CONTENTTEMPLATE></form></BODY></HTML>