0

我使用 MySQL 数据库设置了一个基本的会员系统,其中包含 3 个表 user_id、user_name 和 user_password。我的 php 代码很简单,因为我是 php 新手,并且会随着我的知识的进步而进一步开发它。我目前正在尝试创建不同的卷,成员、管理员和全局管理员。我对如何从我目前所拥有的东西取得进展有点迷茫。任何意见或建议将不胜感激。

我的基本会员代码

    <?php
session_start();

$errorMessage = '';
if (!empty($_POST['user_name']) && !empty($_POST['user_password'])){
    include 'library/connect.php';

    $user_name = $_POST['user_name'];
    $user_password = $_POST['user_password'];

    $sql = "SELECT user_id FROM Login WHERE user_name = '$user_name' AND user_password = '$user_password'";

    $result = mysql_query($sql) or die('Query failed. ' . mysql_error());
    $row = mysql_fetch_array($result);

    if (mysql_num_rows($result) == 1) {
    $_SESSION['user_logged_in'] = true;
    $_SESSION['id'] = "$row[user_id]";
    header("Location: user/user.php");
    }
        else {
            $errorMessage = 'Sorry, wrong username / password';
            }
                include 'library/close.php';
}
?>
<html>
<head>
</head>
<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="998000"><?php echo $errorMessage; ?></font></strong></p>
<?php
}
?>

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" name="formLogin" id="formLogin">
<table width="400" border="1" align="center" cellpadding="2" cellspacing="2">
<tr>
    <td width="150">User name</td>
    <td><input name="user_name" type="text" id="user_name"></td>
</tr>
<tr>
    <td width="150">Password</td>
    <td><input name="user_password" type="password" id="user_password"></td>
</tr>
<tr>
    <td width="150"></td>
    <td><input name="btnLogin" type="submit" id="btnLogin" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>

总结 我建立了一个基本的会员系统,我希望将其扩展为包括两级安全管理员和全局管理员的 Rolls。

4

1 回答 1

3

好吧,您可以轻松地在表格中添加一个字段,例如

level

并添加一个值,例如 1(基本用户)2(管理员)3(全局管理员)。

当有一个操作可以完成时,例如,只有管理员可以完成,你只需像这样检查它:

if ($user_level >= 2) {

echo 'You can do this...';

}
于 2014-01-05T21:25:07.917 回答