Reputation: 211
I have a php session problem in Firefox
After updating Firefox to Firefox 15 I got a problem in captcha, I test it on all browsers and it works perfectly!
At the top of the php file, I put this line:
$_SESSION['captcha']=rand(1000,9999);
Within the document, I use it to show the random captcha, but it always shows the previous random value not the new one!
- 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'/>";
?>
Upvotes: 2
Views: 342
Reputation: 69937
Instead of generating the random value from your script, storing it in the session and then serving captcha.php, just have captcha.php generate the random value, draw it on the image, and save it in the session.
This way, your captcha value always matches what is shown on the image.
Upvotes: 2
Reputation: 7077
Try this
if (!isset($_SESSION['captcha'])) {
$_SESSION['captcha']=rand(1000,9999);
}
Upvotes: 0