Home > Backend Development > PHP Tutorial > 帮我看一下哪里错了,怎么输都是显示输入错误

帮我看一下哪里错了,怎么输都是显示输入错误

WBOY
Release: 2016-06-20 12:26:38
Original
1097 people have browsed it

nbsp;html>


    
    



    验证码:
        require('03.php');
    ?>

    提交
    
    if(isset($_POST['submit']))
    {
        session_start();
        $checkstr=$_SESSION['yzm']; //使用$_SESSION变量获取EX4_14_image.php页面上的验证码
        $str=$_POST['check']; //用户输入的字符串
        if(strcasecmp($str,$checkstr)==0) //不区分大小写进行比较
            echo "<script>alert('验证码输入正确!');</script>";
        else
            echo "<script>alert('输入错误!');</script>";
    }
    ?>





03.php
session_start();
function a($type, $length ,$clear){
    $nums=range(0,9);
    $xxzm=range('a','z');
    $dxzm=range('A','Z');
    $igorne=array('0','o','1','l');
    $chars=array();
    if($type==1)
        $chars=$nums;
    if($type==2)
        $chars=array_merge($nums,$xxzm);
    if($type==3)
        $chars=array_merge($nums,$xxzm,$dxzm);
    if($clear==true)
        $chars=array_diff($chars,$igorne);
    $keys=array_rand($chars,$length);
    $code="";
    foreach($keys as $key)
        $code=$code.$chars[$key];
    return $code;

}

$yzm=a(3,5,true);
$_SESSION['yzm']=$yzm;
echo $yzm;
?>


回复讨论(解决方案)

你在程序文件的开始处 和 接收提交的代码段中打印出  $_SESSION['yzm'] 和 $_POST['check'] 就会知道问题的所在了

require('03.php'); //产生验证码,并保存于 $_SESSION
而 $checkstr=$_SESSION['yzm']; //使用$_SESSION变量获取EX4_14_image.php页面上的验证码
总是在其后运行,显然获得的只是最新设置的内容

要怎么改呢?

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template