简体   繁体   中英

PHP : Login in to the admin page

I am trying to login into the admin and lecturer page in the following code.But it is not working properly.When i login after entering loginid and password, click on submit , no error occured. admin.php

<?php 
session_start();
if(isset($_SESSION["userid"]))
{
    if($_SESSION["type"]=="admin")
    {
    header("Location: dashboard.php");
    }
    else
    {   
    header("Location: lectureaccount.php");
    }
}

include("header.php"); 
include("conection.php");
if(isset($_POST["uid"]) && isset($_POST["pwd"]) )
{
//  echo "sdfsd".   $_POST[uid];
$result = mysql_query("SELECT * FROM administrator WHERE adminid='$_POST[uid]'");
while($row = mysql_fetch_array($result))
  {
$pwdmd5 = $row["password"];
  }

if(md5($_POST["pwd"])=='$pwdmd5')
{
    $_SESSION["userid"] = $_POST["uid"];
    $_SESSION["type"]="admin";
    header("Location: dashboard.php");
}
else
{
$log =  "Login failed.. Please try again..";
}
}

if(isset($_POST["luid"]) && isset($_POST["lpwd"]))
{

$result = mysql_query("SELECT * FROM lectures WHERE lecid='$_POST[luid]'");
    while($row = mysql_fetch_array($result))
     {
$pwdm= $row["password"];
$_SESSION["lecname"] = $row["lecname"];
$_SESSION["coid"] = $row["courseid"];
    }
//echo"pwd". md5($_POST["lpwd"]);

if(md5($_POST["lpwd"])==$pwdm)
    {
        //echo $_POST["lpwd"];
    $_SESSION["userid"] = $_POST["luid"];
    $_SESSION["type"]=="lecturer";
    header("Location: lectureaccount.php");
    }
else
    {
        $log12 =  "Login failed.. Please try again..";
    }
}
?>
<section id="page">
<header id="pageheader" class="normalheader">
<h2 class="sitedescription">
</h2>
</header>

<section id="contents">

<article class="post">
  <header class="postheader">
  <h2><u>Admin Login</u></h2>
   <?php $log = isset($_POST['log']) ?>
  <h2><?php echo $log;?></h2>
  </header>
  <section class="entry">
  <form action="admin.php" method="post" class="form">
   <p class="textfield">
      <label for="author">
             <small>Admin Login ID (required)</small>
          </label>
           <input name="uid" id="uid" value="" size="22" tabindex="1" type="text">
   </p>
   <p class="textfield">
   <label for="email">
              <small>Password (required)</small>
          </label>
       <input name="pwd" id="pwd" value="" size="22" tabindex="2" type="password">
   </p>
   <p>
     <input name="submit" id="submit" tabindex="5" type="image" src="images/submit.png">
     <input name="comment_post_ID" value="1" type="hidden">

   </p>
   <div class="clear"></div>
</form>
  <form action="admin.php" method="post" class="form">
<div class="clear">
<hr />
  <header class="postheader">
    <h2><u>Lectures Login</u></h2>
   <?php $log12 = isset($_POST['log12']) ?>
   <h2><?php echo $log12;?></h2>
  </header>
  <section class="entry">

      <p class="textfield">
        <label for="author2"> <small><br />
          Lecture Login ID (required)</small> </label>
        <input name="luid" id="luid" value="" size="22" tabindex="3" type="text" />
      </p>
      <p class="textfield">
        <label for="email2"> <small>Password (required)</small> </label>
        <input name="lpwd" id="lpwd" size="22" tabindex="4" type="password" />
      </p>
      <p>
        <input name="submit2" id="submit2" tabindex="5" type="image" src="images/submit.png" />
        <input name="comment_post_ID2" value="1" type="hidden" />
      </p>
      <div class="clear"></div>
    </form>
    <div class="clear"></div>
  </section>
</div>
</section>
</article>
</section>

<?php 
include("adminmenu.php");
include("footer.php"); ?>

Database: table fields in administrator are: adminid,password,adminname,address,contactno table fields in lectures are: lecid,password,courseid,lecname,gender,address,contactno.

Please provide solution for this issue.

instead of using this code

if(md5($_POST["pwd"])=='$pwdmd5')   

use this

if(md5($_POST["pwd"])==$pwdmd5)

In the first case, the hashed pasword is compared to the string $pwdmd5 , in the second to the content of $pwdmd5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM