Ciao forum, ho un problema con questo codice che crea un immaggine captcha ma quando confronto $_SESSION['control'] con quello inserito nel form dice sempre che è sbagliato.
Ho anche notato una cosa quando faccio echo $_SESSION['control'] e aggiorno fa vedere il captcha che si era visualizzato prima
Codice PHP:
<?php

$x 
200;
$y 75;

$crypt sha1(microtime() * time());


$str substr($crypt,0,6);

$code $str;
$space $x / (strlen($code)+1);
$img imagecreatetruecolor($x,$y);
$bg imagecolorallocate($img,255,255,255);
$border imagecolorallocate($img,0,0,0);
$colors[] = imagecolorallocate($img,128,64,192);
$colors[] = imagecolorallocate($img,192,64,128);
$colors[] = imagecolorallocate($img,108,192,64);
imagefilledrectangle($img,1,1,$x-2,$y-2,$bg);
imagerectangle($img,0,0,$x-1,$y-2,$border);
for (
$i=0$istrlen ($code); $i++)
{
$color $colors[$i count($colors)];
imagettftext($img,28+rand(0,8),-20+rand(0,40),($i+0.3)*$space,50+rand(0,10),$color,'BRLNSR.TTF',$code{$i});
}
for(
$i=0;$i<400;$i++)
{
$x1 rand(3,$x-3);
$y1 rand(3,$y-3);
$x2 $x1-2-rand(0,8);
$y2 $y1-2-rand(0,8);
imageline($img,$x1,$y1,$x2,$y2,$colors[rand(0,count($colors)-1)]);
}
$_SESSION['control'] = sha1($str);
 
header("Content-type: image/png");
imagepng($img);

?>