我在firefox中的php会话有问题
我在Firefox中遇到了一个php会话问题 在将Firefox升级到Firefox 15后,我发现captcha有问题,我在所有浏览器上测试了它,它工作得非常好 在php文件的顶部,我放置了以下行:我在firefox中的php会话有问题,php,firefox,Php,Firefox,我在Firefox中遇到了一个php会话问题 在将Firefox升级到Firefox 15后,我发现captcha有问题,我在所有浏览器上测试了它,它工作得非常好 在php文件的顶部,我放置了以下行: $_SESSION['captcha']=rand(1000,9999); 在文档中,我使用它来显示随机验证码,但它总是显示以前的随机值,而不是新值 -captcha.php: <?php session_start(); header('content-type:ima
$_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);
?>
试试这个
if (!isset($_SESSION['captcha'])) {
$_SESSION['captcha']=rand(1000,9999);
}
与其从脚本生成随机值,将其存储在会话中,然后提供captcha.php,不如让captcha.php生成随机值,将其绘制在图像上,并将其保存在会话中 这样,您的验证码值始终与图像上显示的内容相匹配
if (!isset($_SESSION['captcha'])) {
$_SESSION['captcha']=rand(1000,9999);
}