【问题标题】:something wrong with my php session in firefox我在 Firefox 中的 php 会话有问题
【发布时间】:2012-09-07 00:17:00
【问题描述】:

我在 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'/>";
?>

【问题讨论】:

    标签: php firefox


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      试试这个

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-15
        • 2010-11-24
        • 1970-01-01
        相关资源
        最近更新 更多