douzhi19900102 2015-09-08 19:17
浏览 38

检查数据库中的信息

I'm Trying To Let users Login

on control page:

<?php include"files/header.php";?>
<?php
global $tf_handle;
$u_name  = strip_tags($_POST['u_name']);    
$u_pass  = md5($_POST['u_pass']);       
if(isset($_POST['login']))
{
    if(empty($u_name) or empty($u_pass))
    {
        echo"
            <div class='error'>Fill the The Form PLease</div><br />
            ";      
    }
    else
    {
        $sqlquery = mysqli_query($tf_handle,"SELECT * FROM user WHERE u_name = '".$u_name."' AND u_pass = '".$u_pass."'");
        if(mysqli_num_rows($sqlquery) > 0)
        {
            $fetchLquery = mysqli_fetch_object($sqlquery);
            print_r($fetchLquery);
            $uid = $fetchLquery->u_id;
            $uname = $fetchLquery->u_name;
            echo "$uname";
            $upass = $fetchLquery->u_pass;
            if($uname != $u_name )
            {
                //AND $upass != $u_pass
                echo"
                <div class='error'>wrong name</div><br />
                ";  
            }
            else
            {
                setcookie("uid",$uid,time()+60*60*24);
                setcookie("login",1,time()+60*60*24);
                echo"
                <div class='error'>Done !</div><br />
                ";
                header('Refresh: 3;url=index.php'); 
            }
        }
        else
        {
            echo"
                <div class='error'>Wrong information</div><br />
                ";              
        }
    }
}
?>  
            <div class="rightco">
            <div class="B_t_in">    
                    <div class="title_b">
                        <h3>Pen Testing</h3>
                    </div>  
                    <div class="info">
                        By : ~Hacker~
                        Date :30/5/2015  
                    </div>
            </div>  


                <table class="tb" width="100%" border="0" >
                    <tr>
                        <td width="20%"><div class="pic"><img src="http://3.bp.blogspot.com/-xUY6gP4Uhgw/U7ADSxKjwBI/AAAAAAAABM8/uVAbk_D06Wg/s1600/php-framework1+copy.png" alt="" /></div> </td>
                        <td width="80%">
                            <p>
                                Test Test Test Test Test Test Test Test TestTest Test Test Test Test Test Test Test Tes
                                Test Test Test Test Test Test Test Test Test
                            </p>
                        </td>
                    </tr>   
                </table>

                <div class="more"><a href="#">Read More !</a></div>

            </div>
<?php include"files/block.php";?>
<?php include"files/footer.php";?>          

The Result is

Wrong Name

& i tried to echo the Variables to check it

$fetchLquery  = stdClass Object ( [u_id] => 3 [u_name] => memo [u_pass] => 202cb962ac59075b964b07152d234b70 [u_email] => jankeh@yahoo.com [u_ulv] => 1 )

$uname = 'memo'

This condition if($uname != $u_name ) shouldn't be executed

i don't know what's the reason of this problem !

i should check another thing ?

  • 写回答

1条回答 默认 最新

  • dongsechuan0535 2015-09-08 19:26
    关注

    You don't need to be checking if the names match anyway.

    Why?

    Your query will only return data if the username and password match those that you have put into the query. You're doing the same thing twice - once in SQL and again in PHP!

    You just need to check if anything has been returned from the query. If it has, you know it's a match! :)

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用