我在Firefox中的php会话有问题

时间:2012-09-07 00:17:01

标签: php firefox

我在Firefox中有一个php会话问题

将Firefox更新到Firefox 15后,我遇到了验证码的问题,我在所有浏览器上测试它,它完美无缺!

在php文件的顶部,我把这行:

$_SESSION['captcha']=rand(1000,9999); 

在文档中,我用它来显示随机验证码,但它总是显示以前的随机值而不是新的随机值!

- captcha.php

<?php
    session_start();
    header('content-type:image/jpeg');
    $text=$_SESSION['captcha'];

    $font=34;
    $height=40;
    $width=100;
    $rand=rand(-7,7);
    $image=imagecreate($width,$height);
    imagecolorallocate($image,255,255,255);
    $text_color=imagecolorallocate($image,0,50,80);

    for($i=1;$i<=8;$i++){
        $x1=rand(1,100);
        $y1=rand(1,100);
        $x2=rand(2,100);
        $y2=rand(1,100);

        imageline($image,$x1,$y1,$x2,$y2,$text_color);
    }

    $fontfile='./angelicwar.ttf';
    imagettftext($image,$font,$rand,10,35,$text_color,$fontfile,$text);
    imagejpeg($image);
?>

<?php
    session_start();
    $_SESSION['captcha']=rand(1000,9999);
    echo "<img src='captcha.php'/>";
?>

2 个答案:

答案 0 :(得分:2)

不是从脚本生成随机值,将其存储在会话中然后提供captcha.php,而是让captcha.php生成随机值,将其绘制在图像上,并将其保存在会话中。

这样,您的验证码值始终与图像上显示的值匹配。

答案 1 :(得分:0)

试试这个

    if (!isset($_SESSION['captcha'])) {
       $_SESSION['captcha']=rand(1000,9999); 
    }