如果管理员已经登录,我不想向管理员显示登录页面。如果我想在管理员进入管理员登录页面时将管理员重定向到主页该怎么办。为了您的信息,我已将header.php
管理员登录后的每个管理员页面都包含在内。非常感谢您的帮助!谢谢!
下面显示了我的header.php
编码的一部分:
<?php
session_start();
if(!isset($_SESSION['name']) or (!isset($_SESSION['password']))
or $_SESSION['name'] == '' or $_SESSION['password'] == '' )
{
header('Location: index.php');
}
?>
下面显示了我的管理员登录页面编码:
<form method="post" action="login_now.php" name="form1" id="form1" onSubmit="MM_validateForm('Name','','R','Password','','R','Security_code','','R');return document.MM_returnValue">
<table style="width: 100%;">
<tbody>
<tr>
<td style="text-align: center;" rowspan="4"><img src="../admin/images/login.png" alt="Please enter your login details."></td>
</tr>
<tr>
<td>
Username<span class="required">*</span>
<br>
<input type="text" class="form-control" style="width: 150px; height: 20px" name="Name" id="Name" class="inputstyle"/>
<br>
<br>
Password<span class="required">*</span>
<br>
<input type="password" class="form-control" style="width: 150px; height: 20px" name="Password" id="Password" class="inputstyle"/>
<br>
</td>
</tr>
<tr>
<td> <br> </td>
</tr>
<tr>
<td align="right" width="240px">
<input type="submit" value="Login" class="buttons" />
下面显示了我的login_now.php
编码:
<?php session_start();
ob_start();
include("../DBScripts/DB.php");
$adminName = $_POST['Name'];
$adminPassword = $_POST['Password'];
$Security = $_POST['Security_code'];
$hidden = $_POST['Security_required'];
$conn = dbConnect();
if (!$conn)
die("Couldn't connect to MySQL");
$query = "select * from user where usernm='$adminName' and userpw='$adminPassword'";
$result = mysql_query($query, $conn);
$row = mysql_fetch_array($result);
if (mysql_num_rows($result) > 0 && $row['userty']== user && $Security == $hidden)
{
$_SESSION['name'] = $adminName;
$_SESSION['password'] = $adminPassword;
header ('Location: ../Users/home_user.php');
}
else if(mysql_num_rows($result) > 0 && $row['userty']== admin && $Security == $hidden)
{
$_SESSION['name'] = $adminName;
$_SESSION['password'] = $adminPassword;
header('Location: adminindex.php');
}
else
{
header('Location: index.php');
}
?>