我在自己的电脑上运行验证码是显示的,怎么我上传到网上空间就不显示啦,是什么原因啊?

解决方案 »

  1.   

    注释掉声明数据类型的 header 函数,用浏览器直接运行生成程序
      

  2.   


    <?php
        //随机字符串种子,可以换成字母或其他英文字符
        $glbVerifySeed = "AbcDefGhijkL1234567890mnOpqRstuvwxYz";
        main();
            
        function main() {
            session_start();
            
            $verifyCode = getRandomCode();
            $_SESSION["verifyCode"] = $verifyCode;
            $imgWidth = $_REQUEST["width"];
            $imgHeight = $_REQUEST["height"];
            $imgFont = $_REQUEST["font"];
            
            if($imgWidth == "") $imgWidth = 50;
            if($imgHeight == "") $imgHeight = 20;
            if($imgFont == "") $imgFont = 6;
            doOutputImg($verifyCode, $imgWidth, $imgHeight, $imgFont);
        }
        
        //获取随机数字字符串
        function getRandomCode($length=4) {
            global $glbVerifySeed;
            
            $bgnIdx = 0;
            $endIdx = strlen($glbVerifySeed)-1;
            
            $code = "";
            for($i=0; $i<$length; $i++) {
                $curPos = rand($bgnIdx, $endIdx);
                $code .= substr($glbVerifySeed, $curPos, 1);
            }
            
            return $code;
        }
        
        //输出校验码图像
        function doOutputImg($string, $imgWidth, $imgHeight, $imgFont,
            $imgFgColorArr=array(0,0,0), $imgBgColorArr=array(255,255,255)) {
            $image = imagecreatetruecolor($imgWidth, $imgHeight);        //用白色背景加黑色边框画个方框
            $backColor = imagecolorallocate($image, 255, 255, 255);
            $borderColor = imagecolorallocate($image, 255, 255, 255);
            imagefilledrectangle($image, 0, 0, $imgWidth - 1, $imgHeight - 1, $backColor);
            imagerectangle($image, 0, 0, $imgWidth - 1, $imgHeight - 1, $borderColor);        $imgFgColor = imagecolorallocate ($image, $imgFgColorArr[0], $imgFgColorArr[1], $imgFgColorArr[2]);
            doDrawStr($image, $string, $imgFgColor, $imgFont);
            doPollute($image, 64);        header('Content-type: image/png');
            imagepng($image);
            imagedestroy($image);
        }    //画出校验码
        function doDrawStr($image, $string, $color, $imgFont) {
            $imgWidth = imagesx($image);
            $imgHeight = imagesy($image);
            
            $count = strlen($string);
            $xpace = ($imgWidth/$count);
            
            $x = ($xpace-6)/2;
            $y = ($imgHeight/2-8);
            for ($p = 0; $p<$count;  $p ++) {
                $xoff = rand(-2, +2);
                $yoff = rand(-2, +2);
                $curChar = substr($string, $p, 1);
                imagestring($image, $imgFont, $x+$xoff, $y+$yoff, $curChar, $color);
                $x += $xpace;
            }        return 0;
        }
        
        //画出一些杂点
        function doPollute($image, $times) {   
            $imgWidth = imagesx($image);
            $imgHeight = imagesy($image);
            for($j=0; $j<$times; $j++) {
                $x = rand(0, $imgWidth);
                $y = rand(0, $imgHeight);
                
                $color = imagecolorallocate($image, rand(0,255), rand(0,255), rand(0,255));
                imagesetpixel($image, $x, $y, $color);
            }
        }
    ?>验证码是这样写的。<?
    require_once('lib07/function_form.inc.php');
    require_once('lib07/config.inc.php');
    if(!defined('dbzz_net')) {
    exit('Access Denied');
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title><?=$global_websitename;?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <script language="javascript">
    <!--
    function FormCheck() 
    {  if (myform.userid.value=="")
      {
        alert("请您填写用户ID!");
        document.myform.userid.focus();
        return false;
      }
    var filter=/^\s*[A-Za-z0-9_-]{4,20}\s*$/;
    if (!filter.test(document.myform.userid.value)) { 
    alert("用户名填写不正确,请重新填写!可使用的字符为(A-Z a-z 0-9 下划线 减号)长度不小于4个字符,不超过20个字符,注意不要使用空格。"); 
    document.myform.userid.focus();
    //document.myform.username.select();
    return false; 
    }   
     if (myform.pwd.value=="")
      {
        alert("请您填写密码!");
        document.myform.pwd.focus();
        return false;
      }
      if(myform.check.value==""){
       alert ("验证码必须填写!");
       myform.check.focus();
       return false;
    }
    var filter=/^\s*[A-Za-z0-9_-]{4,20}\s*$/;
    if (!filter.test(document.myform.pwd.value)) { 
    alert("密码填写不正确,请重新填写!可使用的字符为(A-Z a-z 0-9 下划线 减号)长度不小于4个字符,不超过20个字符,注意不要使用空格。"); 
    document.myform.pwd.focus();
    document.myform.pwd.select();
    return false; 
    }   
       
      return true;  
    }//function shutwin(){opener=null;self.close();}
    //
    //function showme1() {
    //window.open("","pop","scrollbars=no,status=yes,resizable=yes,top=0,left=0,width="+(screen.availWidth-10)+",height="+(screen.availHeight-30)+",channelmode=no");
    //shutwin();
    //}function textLimitCheck(thisArea, maxLength)
    {
        if (thisArea.value.length > maxLength)
    {
          alert(maxLength + ' 个字限制. \r超出的将自动去除.');
          thisArea.value = thisArea.value.substring(0, maxLength);
          thisArea.focus();
        }
        /*回写span的值,当前填写文字的数量*/
      }function change()  
    {  
    var img =document.getElementById("codeimg");  
    img.src=img.src+"?";  
    }  
    //-->
    </script>
    </head><body style="background:#145597 url(myimages/one/login_back.gif) repeat-x top;" scroll=no>
    <table width="1004" height="618" border="0"  cellpadding="0" cellspacing="0" background="myimages/1/loginback.jpg">
      <tr>
        <td align="center" ><table width="498" height="222" border="0" cellpadding="0" cellspacing="9" bgcolor="215992">
            <tr>
              <td background="myimages/1/loginback_mid.jpg" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="40"  class="websitename">&nbsp;&nbsp;&nbsp;&nbsp;金科网络公司OA系统登录</td>
                  </tr>
                  <tr>
                    <td><form name="myform" method="post" onSubmit="return FormCheck();" action="userinfo/login.php">
                        <table width="100%" border="0" cellspacing="0" cellpadding="2">
                          <tr> 
                            <td width="25%" height="26" align="right"><font color="#0057AE">账 号:</font></td>
                            <td width="38%"><input name="userid" type="text" id="Uname" style="width:148px;padding-bottom:2px;padding-left:3px;line-height:22px;margin:0px auto;" tabindex=1 size="18" maxlength="20"></td>
                            <td width="37%" rowspan="3"><input type="image" src="myimages/1/loginbutton.gif" name="Submit" style="height:62px;width:62px;border:0px;" width="62" height="62" tabindex=3 value="-立刻登录-" >
                             </td>
                          </tr>
                          <tr> 
                            <td height="26" align="right"><font color="#0057AE">密 码:</font></td>
                            <td><input name="pwd" type="password" id="Upass" style="width:148px;padding-bottom:2px;line-height:22px;padding-left:3px;margin:0px auto;" tabindex=2 size="20" maxlength="20" ></td>
                          </tr>
      <tr> 
                            <td height="26" align="right"><font color="#0057AE">验证码:</font></td>
                            <td><input type="text" name="check" style="width:148px;padding-bottom:2px;padding-left:3px;line-height:22px;margin:0px auto;" tabindex=1 size="18" maxlength="20"></td></tr>
    <tr><td>&nbsp;</td><td><img src="userinfo/Verifycode.php" onClick="this.src='userinfo/Verifycode.php?rand='+Math.random()*5;" style="cursor:pointer; width:60px; height:20px;" id="codeimg"/>&nbsp;<a href="javascript:change();" style="cursor:pointer;">看不清楚,换一张</a></td>
                          </tr>
                        </table>
                      </form></td>
                  </tr>
                  <tr>
                    <td height="40" style="color:#53a3c6;line-height:22px;">&nbsp;&nbsp;&nbsp;&nbsp;业务部专用<br>&nbsp;&nbsp;&nbsp;&nbsp;
                   </td>
                  </tr>
                </table></td>
            </tr>
          </table></td>
      </tr>
    </table>
    </body>
    </html>调用是这样调用的
      

  3.   

    这样写在本地只要把wamp里面的php_gd2选上就行显示啦,怎么上传到空间后就没有显示啦呢?请帮帮我,谢谢!
      

  4.   

    Notice:  Undefined index: width in .... on line 11
    Notice:  Undefined index: height in ... on line 12
    Notice:  Undefined index: font in ... on line 13而你只有 <img src="userinfo/Verifycode.php" ...
    并没有传入参数