【问题标题】:problem with captcha验证码问题
【发布时间】:2011-01-08 15:31:12
【问题描述】:

我遇到了验证码问题。在我提供验证码后,在我的联系我们表单中显示错误的验证码。我该如何解决这个问题

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);
?>

这是我的 js 验证

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

谁能说说它有什么问题。谢谢在adv

【问题讨论】:

    标签: php javascript jquery html css


    【解决方案1】:

    有一件事是你应该使用 session 而不是 cookie。

    另一件事是你可能忘了检查 md5。

    【讨论】:

    • 我用md5检查过,但还是有问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 1970-01-01
    • 2022-07-20
    • 1970-01-01
    • 2011-05-24
    • 2011-11-12
    相关资源
    最近更新 更多