日期:2014-05-17  浏览次数:20445 次

关于验证码问题
老是获取不得到值。

于是造成老是无法正确判断session_id
别人的浏览器问题都没问题,就是我的机器有问题。

后来这次换了新主机,新系统,问题又出现了,崩溃了。

不知道是啥原因?


php生成验证码 myauth.php
PHP code

 class auth{  
             public function auth()
              {
                     session_start();                               //启动session
                     $str="abcdefghijkmnpqrstuvwxyz23456789";   /*生成一个4位随机数  */
                     for($i=0;$i<4;$i++){
                                 $num.=substr($str,rand(0,29),1);
                        }
                      $_SESSION['code']=$num;   //将随机数保存到session中
                      $im=imagecreate(60,25);    //创建一个60*20的图像
                      $white=ImageColorAllocate($im,255,255,255);  //设置图像的背景色为白色
                      $blue=ImageColorAllocate($im,0,0,255);   //设置图像中文本颜色为蓝色
                      /* 将多个颜色不同的*号添加到图像中  */
                      for($i=1;$i<200;$i++){
                                                 $x=rand(1,60-9);
                                                $y=rand(1,20-6);
                                                $color=imagecolorallocate($im,rand(200,255),rand(200,255),rand(200,255));
                                                imagechar($im,1,$x,$y,"*",$color);
                            }
                                /*将4位随机数添加到图像中,添加的位置不固定  */
                       $strx=rand(3,8);
                       for($i=0;$i<4;$i++){
                                    $strpos=rand(1,6);
                                    imagestring($im,5,$strx,$strpos,substr($num,$i,1),$blue);
                                    $strx+=rand(8,12);
                            }
                      header ("Content-type: image/gif");  //设置输出图像的格式
                      imagegif($im);   //输出图像
                      imagedestroy($im);  //释放图像资源
                     //return $_SESSION['code'];
                      exit;
            }
  }
  $auth = new  auth();



html显示
HTML code

<tr>
                      <td style="color: white;">验证码:</td><td><span><input type="text" name="check"  id="check"/>
                      <img id="img" onclick="refashImage()" src="{$baseurl}/auth.php" style="width:65px;height:20px;font-size:12px; vertical-align: middle;"  name="auth"/>
                      </span></td><td><a style="font-size: 12px;color:white">点击图片刷新</a></td>
                    </tr>





------解决方案--------------------
别人没问题,你有问题,那么应该换的是你自己的系统/浏览器。另外确认一下是多少个别人 比例是多少 这样就清楚到底是自己的系统还是服务器的代码等有问题。

------解决方案--------------------
检查session.autostart是否开启了。
------解决方案--------------------
探讨

机器都新换了,系统也是新的。

------解决方案--------------------
首先检查 检查session.autostart是否开启了
不过 别人的浏览器都没问题,就是我的机器有问题。应该不是这个原因
你得检查你的浏览器是否允许 cookie

代码本身没有问题

如果 html显示 src="{$baseurl}/auth.php" 那显然是不对的
模板里这样还差不多
------解决方案--------------------
还有可能是路径这部分写错了

<img id="img" onclick="refashImage()" src="<?php echo $baseurl;>/auth.php"... ;