0

我想知道是否有人可以帮助我 - 我已经成功创建了一个允许用户(学生)登录的登录系统。我的系统还需要管理员登录,管理员有权查看学生没有的页面。管理员和学生信息都来自两个不同的表。下面是我用于学生登录的代码(有两个不同的页面 - 用户和登录)。我对如何实现管理员登录感到困惑。感谢您的帮助!(管理员将使用“adminnum”和“adminpassword”登录。

登录.php

<?php

include "core/init.php";
include "includes/content.php";

if (empty($_POST) === false) {
$studentemail = $_POST ['studentemail'];
$studentpassword = $_POST ['studentpassword'];

if (empty($studentemail) === true || empty($studentpassword) === true) {
    $errors[] = "You need to enter an email address and password"; 
} else if (user_exists($studentemail) === false) {
    $errors[] = "We can't find that email address. Have you registered?";
} else {

    if (strlen($studentpassword) > 32) {
        $errors[] = 'Password too long';
        }

    $login = login($studentemail, $studentpassword);
    if ($login === false) {
        $errors[] = 'That email/password combination is incorrect';
    } else {
        $_SESSION['studentid'] = $login;
        header('Location: index.php');
        exit();
    }
}
} else {
$errors[] = 'No data received';
}
include "includes/overall/overall_header.php";
if (empty($errors) === false) {
?>
<h2> We tried to log you in, but...</h2>    

<?php
echo output_errors($errors);
}
?>
    <center><input id="submit" type="submit" value="Back" onclick="location.href='Login2.php'"></center>
<?php
include "includes/overall/overall_footerloggedout.php";
?>

用户.php

<?php
function logged_in() {
return (isset($_SESSION['studentid'])) ? true : false;
}

function user_exists($studentemail) {
$studentemail = sanitize($studentemail);
$query = mysql_query("SELECT COUNT(`studentid`) FROM `student` WHERE `studentemail` 
         = '$studentemail'");
return (mysql_result($query, 0) == 1) ? true : false;
}

function studentid_from_student ($studentemail) {
$studentemail = sanitize($studentemail);
return mysql_result(mysql_query("SELECT `studentid` FROM `student` WHERE      `studentemail` = '$studentemail'"), 0, 'studentid');
}
`function login($studentemail, $studentpassword) {
$studentid = studentid_from_student($studentemail);

$studentemail = sanitize($studentemail);
$studentpassword = md5($studentpassword);

return (mysql_result(mysql_query("SELECT COUNT(`studentid`) FROM `student` WHERE   `studentemail` = '$studentemail' AND `studentpassword` = '$studentpassword'"), 0) == 1) ?   $studentid : false;

}
?>
4

2 回答 2

0

我建议改变你的逻辑,从两个不同的表中提取用户和管理员。仅将它们放在一个表中,但所有用户都应包含列flag,例如,其中 flag=1 是 ADMIN,flag=0 是 USER。

于 2013-04-04T13:37:53.313 回答
0

我只能建议,因为我不是 php 编码器,但过去做过一些事情是在您的数据库中添加另一个字段,您将在其中为用户设置权限级别(普通成员为 0,管理员为 1)。完成之后,只需通过我几乎不知道的 php 编码将其添加到您的用户脚本中。希望能有所帮助。

于 2013-04-04T13:45:35.253 回答