zzdcx89 2022-04-14 16:25 采纳率: 100%
浏览 116
已结题

登录功能无法实现的问题

最近在学习如何实现登录功能,按照书上的代码制作完后发现验证码图片不显示,试了很多方法都无法显示验证码图片,于是我在网上搜了一个验证码的代码添加尝试后发现可以实现了,但是现在的问题是,数据库中的用户名和密码设置没有问题,但在登录界面输入用户名密码和验证码后无法实现登录功能,验证代码没有报错,请问可以帮我找一下到底哪里出问题了吗,我弄了一天了也弄不好。谢谢!
这个是登录界面和登陆界面的代码:

img

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
//连接数据库
require_once'conn.php';
?>
<table width="209" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="153"><table width="209" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td height="33" colspan="3">用户系统:</td>
    </tr>
    <tr>
    <td width="15">&nbsp;</td>
        <td width="177"><table width="180" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
         <td valign="top"><table width="99%" height="100" border="0" align="center" cellpadding="0" cellspacing="1">
             <tr>
             <td><table width="180" height="100" border="0" align="center" cellpadding="0" cellspacing="0">
                 <tr>
                 <td><table width="180" border="0" cellpadding="0" cellspacing="0">
                <script language="javascript">
                    function chkuserinput(from){
                        if(from.username.value==""){
                            alert("请输入用户名!");
                            from.username.select();
                            return(false);
                        }
                        if(from.userpwd.value==""){
                            alert("请输入用户密码!");
                            from.userpwd.select();
                            return(false);
                        }
                        if(from.authcode.value==""){
                            alert("请输入验证码!");
                            from.authcode.select();
                            return(false);
                        }
                        return(true);
                    }
                     </script> 
                     <script language="javascript">
                         function openfindpwd(){
                             
                        window.open("openfindpwd.php","newframe","left=200,top=200,width=200,height=200,menubar=no,toolbar=no,location=no,scrollbars=no,location=no");
                         }
                     </script>
                     <form name="form2" method="post" action="chkuser11111111111111.php" onSubmit="return chkuserinput(this)">
                     <tr>
                     <td height="10" colspan="3">&nbsp;</td>     
                         </tr>
                         <tr>
                         <td width="50" height="20"><div align="right">用户:</div></td>
                         <td height="20" colspan="2"><div align="left">
                             <input type="text" name="username" size="19" class="inputcss" style="background-color: #3AB2D7" 
                                    onMouseOver="this.style.backgroundColor='#ffffff'"
                                    onmouseout="this.style.backgroundColor='#e8f4ff'">    
                             </div></td>
                         </tr>
                         <tr>
                         <td height="20"><div align="right">密码:</div></td>
                         <td colspan="2"><div align="left">
                             <input type="password" name="userpwd" size="19" class="inputcss" style="background-color: #3AB2D7" 
                                    onMouseOver="this.style.backgroundColor='#ffffff'"
                                    onmouseout="this.style.backgroundColor='#e8f4ff'">    
                             </div></td>
                         </tr>
                         <tr>
                         <td height="20"><div align="right">验证:</div></td>
                         <td width="66" height="20"><div align="left">
                             <input type="text" name="authcode" size="10" class="inputcss" style="background-color: #3AB2D7" 
                                    onMouseOver="this.style.backgroundColor='#ffffff'"
                                    onmouseout="this.style.backgroundColor='#e8f4ff'">    
                             </div></td>
                             <td width="64"><div align="left">&nbsp;
                                <img  id="yanzhengma11111111111111111_img" border="1" src="./yanzhengma11111111111111111.php?r=<?php echo rand(); ?>" alt="" width="70" height="30">
                
                <a href="javascript:void(0)" onclick="document.getElementById('yanzhengma11111111111111111_img').src='./yanzhengma11111111111111111.php?r='+Math.random() ">换一个?</a>
            </p>

                                 </div></td> 
                         </tr>
                         <tr>
                         <td height="20" colspan="3"><div align="right">
                             <input type="hidden" value="<?php echo $num;?>" name="num">
                             <input name="submit" type="submit" class="buttoncss" value="提交">
                             <a href="agreereg.php">注册</a>&nbsp;<a href="javascript:openfindpwd()">找回密码</a>&nbsp;
                             </div></td>
                         </tr>     
                     </form>
                     </table></td>
                 </tr>
                 </table></td>
             </tr>
             </table></td>
            </tr>
            </table></td>
        <td width="17">&nbsp;</td>
    </tr>
    <tr>
    <td colspan="3">&nbsp;</td>
    </tr>
    </table></td>    
    </tr>


这个是登陆验证代码,也没有报错:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
//连接数据库
include("conn.php");
$username=$_POST['username'];
$userpwd=md5($_POST['userpwd']);

if (isset($_REQUEST['authcode'])) {
        session_start();
 
        if (strtolower($_REQUEST['authcode'])!==$_SESSION['authcode']) 
        {
            echo"<script>alert('验证码输入错误!');history.go(-1);</script>";
        }
 
        exit;
    }

class chkinput{
    var $name;
    var $pwd;
    
    function chkinput($x,$y){
        $this->name=$x;
        $this->name=$y;
    }
    
    function checkinput(){
        include("conn.php");
        $sql=mysqli_query($conn,"select * from tb_user where name='".$this->name."'");
        $info=mysqli_fetch_array($sql);
        if($info=false){
            echo "<script language='javascript'>alert('不存在此用户!');history.back();</script>";
            exit;
        }
        else{
            if($info['dongjie']==1){
                echo "<script language='javascript'>alert('该用户已经被冻结!');history.back();</script>";
                exit;
            }
            
            
            if($info['pwd']==$this->pwd)
            {
                session_start();
                $_SESSION['username']=$info['name'];
                
                $producelist="";
                
                $quatity="";
                header("location:index.php");
                exit;
            }
        }
    }
}

$obj=new chkinput(trim($username),trim($userpwd));
$obj->checkinput();
?>

登录验证代码中的检验验证码这部分的代码因为之前的书上的代码的验证图片打不开,所以我把验证验证码这部分的内容重新改了一下,其余部分都是根据书上的打的,应该没有错误。

if (isset($_REQUEST['authcode'])) {
        session_start();
 
        if (strtolower($_REQUEST['authcode'])!==$_SESSION['authcode']) 
        {
            echo"<script>alert('验证码输入错误!');history.go(-1);</script>";
        }
 
        exit;
    }

  • 写回答

3条回答 默认 最新

  • CSDN专家-showbo 2022-04-14 16:40
    关注

    题主用下面的 代码测试,密码错误也需要判断过。而且题主密码是md5过的,数据库的密码的记录值确认md5过?明文对比不成功的哟~
    而且构造函数也要改成下,要不php 7+会报错,题主看的教程应该比较老了

    
    <meta charset="utf-8">
    <?php
    //连接数据库
    include("conn.php");
    $username=$_POST['username'];
    $userpwd=md5($_POST['userpwd']);
     
     
    if (isset($_REQUEST['authcode'])) {
            session_start();
     
            if (strtolower($_REQUEST['authcode'])!==$_SESSION['authcode']) 
            {
                echo"<script>alert('验证码输入错误!');history.go(-1);</script>";
            }
     
            exit;
        }
     
    class chkinput{
        var $name;
        var $pwd;
        
        public function __construct($x,$y){
            $this->name=$x;
            $this->pwd=$y;
        }
        
        function checkinput(){
           include("conn.php");
            
            $sql=mysqli_query($conn,"select * from tb_user where name='".$this->name."'");
            $info=mysqli_fetch_array($sql);
            if($info==null){
                echo "<script language='javascript'>alert('不存在此用户!');history.back();</script>";
                exit;
            }
            else{
                if($info['dongjie']==1){
                    echo "<script language='javascript'>alert('该用户已经被冻结!');history.back();</script>";
                    exit;
                }
                
                
                if($info['pwd']==$this->pwd)
                {
                    session_start();
                    $_SESSION['username']=$info['name'];
                    
                    $producelist="";
                    
                    $quatity="";
                    header("location:index.php");
                    exit;
                }
                else  echo "<script language='javascript'>alert('密码错误!');history.back();</script>";
            }
        }
    }
    $obj=new chkinput(trim($username),trim($userpwd));
    $obj->checkinput();
    ?>
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月22日
  • 已采纳回答 4月14日
  • 赞助了问题酬金50元 4月14日
  • 创建了问题 4月14日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度