PHP实现验证码 点击提交后页面没反应 是什么原因?

form.php

<?php
    if (isset($_REQUEST['authcode'])){
        session_start();

        if ($_REQUEST['authcode'] == $_SESSION['authcode']){
            echo "输入正确";
        }else{
            echo "输入错误";
        }
        exit();
    }
?>

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <from method="post" action="./form.php">
        <p>验证码图片:
            <img src="./captcha.php?r=<?php echo rand();?>">
        </p>

        <p>请输入验证码:
            <input type="text" name="authcode" value="">
        </p>

        <p><input type="submit" value="提交" style="padding: 6px 20px;"></p>
    </from>
</body>
</html>

captcha.php

<?php
    session_start();

    $image = imagecreatetruecolor(100,30);
    $bgColor = imagecolorallocate($image,255,255,255);
    imagefill($image,0,0,$bgColor);

/*    for($i=0;$i<4;$i++){
        $font = 6;
        $col = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
        $s = rand(0,9);

        $x = ($i*100/4)+rand(5,10);
        $y = rand(5,10);

        imagestring($image,$font,$x,$y,$s,$col);
    }*/
    /*字母+数字*/
    $captch_code = '';
    for($i=0;$i<4;$i++){
        $font = 6;
        $col = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));

        $data = "abcdefghgkmnpqrstuvwxyABCDEFGHJKLMNPQRSTUVWXYZ123456789";
        $s = substr($data,rand(0,strlen($data)-1),1);
        $captch_code.=$s;

        $x = ($i*100/4)+rand(5,10);
        $y = rand(5,10);

        imagestring($image,$font,$x,$y,$s,$col);
    }
    $_SESSION['authcode'] = $captch_code;

    /*增加点干扰元素*/
    for($i=0;$i<200;$i++){
        $pointColor = imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));
        imagesetpixel($image,rand(1,99),rand(1,29),$pointColor);
    }
    /*增加线的干扰*/
    for($i=0;$i<3;$i++){
        $lineColor = imagecolorallocate($image,rand(80,220),rand(80,220),rand(80,220));
        imageline($image,rand(1,99),rand(1,29),rand(1,99),rand(1,29),$lineColor);
    }
    header('Content-type: image/png');
    imagepng($image);
    imagedestroy($image);


有学过的同学 给指点指点,最容易忽视的问题在哪?

心有猛虎_细嗅蔷薇
浏览 2079回答 3
3回答

西兰花伟大炮

form表单写成from肯定不行啊,哥

慕设计5951087

没发现那里有bug呀!
打开App,查看更多内容
随时随地看视频慕课网APP