Session 会话始终存储上一个值

Session 会话始终存储上一个值,session,Session,我正在开发一个电子邮件发送表单。它有一个验证码安全图像。每当我刷新图像以加载新的验证码时,它总是存储上一个会话值。它从不存储正确的 但在我的localhost中,它工作得很好。多谢各位 class CaptchaSecurityImages { var $font = 'monofont.ttf'; function generateCode($characters) { /* list all possible characters, similar loo

我正在开发一个电子邮件发送表单。它有一个验证码安全图像。每当我刷新图像以加载新的验证码时,它总是存储上一个会话值。它从不存储正确的

但在我的localhost中,它工作得很好。多谢各位

class CaptchaSecurityImages {

    var $font = 'monofont.ttf';

    function generateCode($characters) {
        /* list all possible characters, similar looking characters and vowels have been removed */
        $possible = '23456789bcdfghjkmnpqrstvwxyz';
        $code = '';
        $i = 0;
        while ($i < $characters) { 
            $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
            $i++;
        }

        $_SESSION['securitycode'] = $code;

        return $code;
    }

    function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
        $code = $this->generateCode($characters);
        /* font size will be 75% of the image height */
        $_SESSION['securitycode'] = $code;      
        $font_size = $height * 0.75;
        $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
        /* set the colours */
        $background_color = imagecolorallocate($image, 255, 255, 255);
        $text_color = imagecolorallocate($image, 20, 40, 100);
        $noise_color = imagecolorallocate($image, 100, 120, 180);
        /* generate random dots in background */
        for( $i=0; $i<($width*$height)/3; $i++ ) {
            imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
        }
        /* generate random lines in background */
        for( $i=0; $i<($width*$height)/150; $i++ ) {
            imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
        }
        /* create textbox and add text */
        $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
        $x = ($width - $textbox[4])/2;
        $y = ($height - $textbox[5])/2;
        imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
        /* output captcha image to browser */
        header('Content-Type: image/jpeg');
        imagejpeg($image);
        imagedestroy($image);


    }

}
class-CaptchaSecurityImages{
var$font='monofont.ttf';
函数生成代码($characters){
/*列出所有可能的字符,相似的字符和元音已被删除*/
$PROPERMIBLE='23456789bcdfghjkmnpqrstvwxyz';
$code='';
$i=0;
而($i<$characters){
$code.=substr($problem,mt_rand(0,strlen($problem)-1),1);
$i++;
}
$\会话['securitycode']=$code;
返回$code;
}
函数CaptchaSecurityImages($width='120',$height='40',$characters='6')){
$code=$this->generateCode($characters);
/*字体大小将是图像高度的75%*/
$\会话['securitycode']=$code;
$font_size=$height*0.75;
$image=@imagecreate($width,$height)或die('cannotinitializenewgdimage-stream');
/*定颜色*/
$background\u color=imagecolorallocate($image,255,255);
$text_color=imagecolorallocate($image,20,40,100);
$noise_color=imagecolorallocate($image,100120180);
/*在背景中生成随机点*/
对于($i=0;$ifont,$code)或die('imagettftext函数中的错误');
/*将验证码图像输出到浏览器*/
标题(“内容类型:图像/jpeg”);
图像jpeg($image);
图像销毁($图像);
}
}

这是我用来生成验证码的类。

这里没有太多信息。一些代码怎么样?这在localhost中有效。但不能在服务器上工作。任何人都知道为什么会话值不能被新值替换。