本文介绍了管理员和不同用户的身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

对不起我的英语知识。

我是学生&& php mysql。

以用户身份登录时,它接受我数据库中已经创建的用户表中的任何值(mca)。使用php会话

请解决这个问题

谢谢...



我试过的:



Hello,
sorry for my english knowledge.
am a student && biginer to php mysql.
while login as a user it accepting any values out of the table(mca) in my database which are allready created users. using php session
please solve this problem
thanks...

What I have tried:

#1connect.php

    <?php
mysql_connect('localhost:3306','root','') or die(mysql_error());
mysql_select_db('repository') or die(mysql_error());

?>
#2login.php

<?php
session_start();
if(isset($_POST['submit']))
{
    $name=$_POST['fname'];
    $password=$_POST['password'];
  // $dept=$_POST['department'];
    include 'connectdb.php';
    $rs='SELECT * FROM mca WHERE fname=fname and password=password';
    $res= mysql_query($rs) or trigger_error(mysql_error().$rs);
    if(mysql_num_rows($res))
    {

        $_SESSION['name']=$name;



        $row=  mysql_fetch_array($res);
        if($row['usertype']==0)
        {
        header('location:adminaction.php');
          }

 else {
        echo 'Sorry Your Username or Department is  Invalid';
        header('location:login.php');
        echo "<script> alert('You are entered invalid Username and Department') </script>";
 }

}
}

?>
<?php
include 'header.php';
?>
<div id="intel">
    <ul >
                    <li id="z"><a href="bca.php">HOME </a>
                         </li>
                     <li id="z"><a href="stats.php"> NOTICE</a></li>
                     <li id="z"><a href="uregistration.php">NEW REGISTER</a></li>
            </ul>
</div>
<br>
<div id="container"><div id="number">
        <div id="first1">
            <?php
            if(isset($msg))
            echo '<h2>'.$msg.'</h2>';
            ?>
            <form action="" method="post">
                <table id="ltable">
                    <tr ><th colspan="2" align="center"> <u>* LOGIN *</u> </th></tr>
                    <tr> <td align="right" >USERNAME    : </td><td><input type="text" size="25" name="fname" autofocus required></td></tr>
                    <tr> <td align="right" >PASSWORD   : </td><td><input type="password" size="25" name="password" required></td></tr>
                 <!-- <tr> <td align="right">  DEPARTMENT :</td><td><select name="department">
                                            <option>SELECT</option>
                                            <option>MCA</option>
                                            <option>BCA</option>
                                            <option>MSC.STATS</option>
                                            <option>MSC.MATHS
                                            </option>
                            </select></td></tr>
               -->
                    <tr><td colspan="2" align="center"><input  type="submit" name="submit" value="LOGIN"></td></tr>
                </table>
        </form>
        <h3>  <pre>

                                                Forgotten UserName?<a href="forget.php" align="center">click here</a>

                                                Don't have an account<a href="uregistration.php" >REGISTER NOW</a></pre> </h3>
        </div>
    </div>


</div>
<?php
include 'footer.php';
?>
#3session.php
<?php
    session_start();
   $check_user=$_SESSION['name'];
   $ses_sql=  mysql_query("SELECT * FROM mca WHERE fname='$check_user'");
   $row=  mysql_fetch_array($ses_sql,MYSQL_ASSOC);
   $login_session=$row['fname'];
   if(!isset($_SESSION['name']))
    {
        header('location:login.php');
    }
?>
#4adminaction.php
<?php
include 'include/admin/header.php';
include 'connectdb.php';
include 'session.php';
?>
<div id="container">
    <div id="number">
        <div id="first1">


            <?php
             echo '<h1>'.'welcome'.$login_session.'</h1>';
            echo 'welcome to admin page you will see different views';
            ?>
            <pre>
                                             <h2>  <a href="logout.php"> LOGOUT</a></h2>

            </pre>

        </div>

    </div>

</div>
<?php
include 'include/admin/footer.php';
?>

推荐答案




这篇关于管理员和不同用户的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 04:33