I have this code:
captcha.php:
session_start();
class Captcha {
protected $code;
protected $width = 35;
protected $height = 150;
function __construct() {
$this->code = substr(sha1(mt_rand()), 17, 6);
$_SESSION['captcha'] = $this->code;
}
function getCode(){
return $this->code;
}
function showImage() {
// here comes the code that builds the image.
// it works fine!
}
}
$image = new Captcha();
$image->showImage();
And in my login form I have:
<iframe src="includes/captcha.php" frameborder="0" height="65" width="180"></iframe>
if I print_r($_SESSION), the $_SESSION['captcha'] always in delay : it contains the previous captcha code , and not the current which is being shown.
What should I do?
should be:
As you should be loading the image as an image not as an iframe.
Also your CAPTCHA code if printed out on the parent page will always be the old value, as the new value only gets written when
captcha.phpis loaded which has happened after the main page has loaded so the new session value was not available at that time. So everything otherwise is working fine.