Reputation: 21
I need to get a session variable value and compare it with an input.
here is the code:
<?php
echo "<img src='captchas.php'><br><center><input type='text' size='10' name='check' id='postcaptcha' onChange='validatecaptcha();'></center><div id='validationforcaptcha'></div>";
$captchacode = $_SESSION['newcode'];
echo "<input type='text' name='sessioncaptcha' id='sessioncaptcha' value=$captchacode />";
?>
and here is the captcha.php
<?php session_start(); ob_start();
$img = imagecreatefrompng('IMAGES/black.png');
$numero = rand(100000000, 999999999);
$_SESSION['check23'] = $numero;
$white = imagecolorallocate($img, 255, 255, 255);
imagestring($img, 10, 8, 3, $numero, $white);
header ("Content-type: image/png");
imagepng($img);
?>
i don't know why the $_SESSION['check23'] variable only retrieves the previous captcha code that has been displayed (not what is currently displayed)
Upvotes: 2
Views: 1181
Reputation: 126
Maybe you're assuming that your first script gets executed after captcha.php?
This is what's actually happening:
Try generating the CAPTCHA code in the first script and saving it to $_SESSION['check23']
. You can retrieve $_SESSION['check23']
later in captcha.php to render the appropriate image.
Upvotes: 3