为什么刷新验证码的时候SESSION 会把以前所有的验证码都记录下来?要怎样才能让session只存在一个验证码?
我的SESSION里面会把刷新的验证码全部保存,这样造成验证码永远出错,如何使验证码覆盖啊?

解决方案 »

  1.   

    SESSION['auth_code']=新的验证码 session_start();
    $auth_code = $_SESSION['auth_code'];然后验证 $auth_code 和提交的
    不就不会了?你的验证码怎么设计的?
      

  2.   

    <?php
    session_start();
    header('Content-type:image/png');
    //创建图片
    $im = imagecreate(130,45)or die("Cannot Initialize new GD image stream");
    $bg = imagecolorallocate($im,rand(50,200),rand(0,155),rand(0,155));
    //第一次对imagecolorallocate()的调用会给基于调色板的图像填充背景色$fontColor = imageColorAllocate($im,255,255,255);  //字体颜色
    //$fontstyle = 'Roman.ttf'; 
    $fontstyle = 'C:\WINDOWS\Fonts\arial.ttf';
    //字体样式,这个可以从C:\windows\Fonts\文件夹下找到,我把它放到和Authcode,php文件同一个目录,这里可以替换其他的字体样式//产生随机字符
    for($i=0;$i< 4;$i++)
    {
    $randAsciiNumArray = array(rand(48,57),rand(65,90));
    $randAsciiNum      = $randAsciiNumArray[rand(0,1)];
    $randStr           = chr($randAsciiNum);
    imagettftext($im,30,rand(0,20)-rand(0,25),5+$i*30,rand(30,35),$fontColor,$fontstyle,$randStr);
    $authcode .= $randStr;
    }//用户和用户输入验证码做比较
    $_SESSION['authcode'] = $authcode;//干扰线
    for($i=0;$i<8;$i++)
    {
    $lineColor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
    imageline($im,rand(0,130),0,rand(0,130),145,$lineColor);
    } //干扰点
    for($i=0;$i<250;$i++)
    {
    imagesetpixel($im,rand(0,130),rand(0,145),$fontColor);
    }imagepng($im);
    imagedestroy($im);
    ?>就这个代码,帮忙看看啊。谢了
      

  3.   

    没有引用啊。就直接验证了。<?php
    session_start();
    header("content-type:text/html;charset=utf-8");
    if($yzm==$_SESSION['authcode'])
    {   
    echo "1";
    exit;
    }else{
    echo "0";
    exit;
    }
    ?>这是验证文件。我在这个文件里echo session里的验证码的时候发现新刷新的验证码全跟在后面。。
      

  4.   

    在for循环产生随机验证码之前加:
    $authcode = '';
    试一试。