magna
magna

Reputation: 287

problem with captcha

i have the problem with captcha. in my contact us form after i give the verification code it says wrong captcha.how could i solve this problem

header('Content-type: image/jpeg');

$width = 50;
$height = 24;

$my_image = imagecreatetruecolor($width, $height);

imagefill($my_image, 0, 0, 0xFFFFFF);

// add noise
for ($c = 0; $c < 40; $c++){
    $x = rand(0,$width-1);
    $y = rand(0,$height-1);
    imagesetpixel($my_image, $x, $y, 0x000000);
    }

$x = rand(1,10);
$y = rand(1,10);

$rand_string = rand(1000,9999);
imagestring($my_image, 5, $x, $y, $rand_string, 0x000000);

setcookie('tntcon',(md5($rand_string).'a4xn'));

imagejpeg($my_image);
imagedestroy($my_image);
?>

this is my js validation

if(document.getElementById("captcha").value==""){
            alert("Please type the code shown ");
            document.getElementById("captcha").value="";
            document.getElementById("captcha").focus();
        return false;
    }

can any one say what is the problem with it.thanks in adv

Upvotes: 1

Views: 196

Answers (1)

Amir
Amir

Reputation: 820

One thing is that you should use session instead of cookie.

Another thing is that maybe you forgot to check md5.

Upvotes: 1

Related Questions