实现的功能是:在别人的网站登录进我的系统。在绘制验证码的php页开起session,然后给别人嵌入登录界面的代码包含绘制验证码页,最后提交到我的系统处理。
   遇到的问题是:在火狐里面正常,但ie6,傲游里面输入验证码后提示错误,第二次输入正常进去系统。每次新打开浏览器输入验证码都会报错,第二次正常,现在不知道什么原因。
    相关代码:
    绘制验证码页:
<?php
header("Content-type: image/PNG");
session_start();//将随机数存入session中
$_SESSION['indexLoginRand']="";
$im = imagecreate(35,15); //制定图片大小$black = ImageColorAllocate($im, 0,0,0); //设定颜色
$white = ImageColorAllocate($im, 255,255,255);imagefill($im,0,0,$white); //区域填充$authnum = rand(1000,9999);
//将四位整数验证码绘入图片
$_SESSION['indexLoginRand']=$authnum;
imagestring($im, 5, 0, -1, $authnum, $black);for($i=0;$i<100;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}ImagePNG($im);
ImageDestroy($im);
?>
嵌入登录页面:
 <form action="http://" method="post">
              <div align="center"><font class="black9">分机号 </font>
                <INPUT name="ci_fax" type="text" class="input">
                <br>
                <font class="black9">密 码 </font>
                <INPUT name="ci_loginpwd" type="password" class="input">
                <br>
                <font class="black9">验证码 </font>
                <INPUT name="ci_rand" type="text" class="input_rand">
                <img src="绘制验证码页"><br>
                <INPUT name="user_login" type="submit" value="登 陆" class="inputbt">
                &nbsp;&nbsp;
                <!--此处的“value”填写返回页面完整地址,用户登录时,填写的分机号码、密码、验证码有错误时,将返回这个页面-->
                <input type="hidden" name="url" value="">
                <INPUT type="button" value="注 册" onClick="location.replace('http://ip/reg.php?agent=1321');" class="inputbt">
                <br>
                <a href="http:///getpassword.php">忘记密码</a>&nbsp;&nbsp;<a href="http:///realcheck.php" >真实验证</a>
              </div>
            </form>           帮我解决问题的送上100分,在线等!!

解决方案 »

  1.   

    提示什么错误?
    接收post的页面
    print_r($_SESSION);
    print_r($_POST['ci_rand']);
    比较一下
      

  2.   

    <?php 
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header("Content-type: image/PNG"); 
    ?>
    可能是cache原因.
    加上这个试试!
      

  3.   

    不如直接用一个图片验证类就行了~
    看一下有没有用~http://www.php002.cn/phpclass/phptupianyanzhengmaleiAbsCaptchalei_10569.html
      

  4.   

    可以取到session值,现在的问题是在打开浏览器后登录界面输入验证码会说验证码错误,进去错误判断跳转别的页面,不关浏览器再次输入验证码才能进系统。ie6,傲游都这样,firefox能正常使用。我想知道这是什么问题?浏览器问题?怎么解决?
      

  5.   

    看不到啊 , 公司除了百度 csdn基本都上不了
      

  6.   

    在接收post的页面比較一下$_SESSION['indexLoginRand']和$_POST['ci_rand']
      

  7.   


    <img src='验证' onClick="this.src='include/code.php#'+new Date().getTime()">打印出处理页面的
    print_r( $_SESSION['indexLoginRand'] ); 看一下是什么情况
      

  8.   

    <img src="http://www.uufax.com/bin/rand.php?act=yes" onClick="this.src='include/code.php#'+new Date().getTime()">
    点完图片结果是一个大红叉
      

  9.   

    加上,然后清除一下浏览器的cache.呵呵.我只能想到是cache的原因.
      

  10.   

    cache 是什么 这个东东我不知道怎么弄啊
      

  11.   

    cache就是缓存,清除浏览器的缓存再试试效果看行不行.
      

  12.   

    我测试了一下,没有发现任何问题.
    session值是能够正确得到的.
    可能是你代码哪块有问题.
    不知道你是如何验证的.
    //code.php<?php 
    session_start();//将随机数存入session中 
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header("Content-type: image/PNG"); $_SESSION['indexLoginRand']=""; 
    $im = imagecreate(35,15); //制定图片大小 $black = ImageColorAllocate($im, 0,0,0); //设定颜色 
    $white = ImageColorAllocate($im, 255,255,255); imagefill($im,0,0,$white); //区域填充 $authnum = rand(1000,9999); 
    //将四位整数验证码绘入图片 
    $_SESSION['indexLoginRand']=$authnum; 
    imagestring($im, 5, 0, -1, $authnum, $black); for($i=0;$i <100;$i++) //加入干扰象素 

    $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255)); 
    imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); 
    } ImagePNG($im); 
    ImageDestroy($im); 
    ?>
    //test2.html
    <form action="index.php" method="post"> 
    <div align="center"> <font class="black9">分机号 </font> 
      <INPUT name="ci_fax" type="text" class="input"> 
      <br> 
      <font class="black9">密 码 </font> 
      <INPUT name="ci_loginpwd" type="password" class="input"> 
      <br> 
      <font class="black9">验证码 </font> 
      <INPUT name="ci_rand" type="text" class="input_rand"> 
      <img src="code.php"> <br> 
      <INPUT name="user_login" type="submit" value="登 陆" class="inputbt"> 
      &nbsp;&nbsp; 
      <!--此处的“value”填写返回页面完整地址,用户登录时,填写的分机号码、密码、验证码有错误时,将返回这个页面--> 
      <input type="hidden" name="url" value=""> 
      <INPUT type="submit" value="注 册"  class="inputbt"> 
      <br> 
      <a href="http:///getpassword.php">忘记密码 </a>&nbsp;&nbsp; <a href="http://l/index.php" >真实验证 </a> 
    </div> 
    </form> 
    //index.php
    <?php
    session_start();
    echo $_POST['ci_rand'] . "<br/>";
    print_r($_SESSION['indexLoginRand']);
    ?>
      

  13.   

    代码我感觉也没问题,用firefox也没有问题,可是我们经理测试用傲游每次新开浏览器输入的验证码都错误
      

  14.   


    <?php
    require_once ("../bin/db.php");
    $ci_fax = trim($_POST['ci_fax']);
    $ci_loginpwd = strtoupper(md5($_POST['ci_loginpwd']));
    $ci_rand = trim($_POST['ci_rand']);
    $return_url = $_POST['url'];
    $ci_rand_system = $_SESSION['indexLoginRand'];
    if (strcmp($ci_rand, $ci_rand_system) != 0) {
    session_unregister('indexLoginRand');
    echo "<script>alert(\"验证码输入错误,请重新输入!\");location.replace('$return_url');</script>";}部分后台源代码 各位大侠参考下,总弹出验证码错误,重新输入
      

  15.   

    你比较两个页面的session 结果,看看有什么问题?
      

  16.   

    你就直接比较下$ci_rand,$ci_rand_system 
    ,看ie6下有问题的那次验证码提交,究竟是这两个东西都是什么样的值。
      

  17.   

    你看一下,你页换显示的验证码和你session中存的是一个值吗?
      

  18.   

    提交页面是不是session没有启动啊!
    isset($_SESSION['indexLoginRand'])看一下;echo $ci_rand;
    echo $ci_rand_system;
    对比一下不就清楚了!
      

  19.   

    步骤:
    1、php 页面里加入清除缓存的代码,上面有人回复了这个代码
    2、这里修改一下<font class="black9">验证码 </font> 
                    <INPUT name="ci_rand" type="text" class="input_rand"> 
                    <img src="绘制验证码页"> <br> 
    修改为:
    <font class="black9">验证码 </font> 
                    <INPUT name="ci_rand" type="text" class="input_rand"> 
                    <img src="绘制验证码页?r=<?php echo rand(0,100)?>"> <br>