doujie7497 2014-01-05 21:20
浏览 6
已采纳

发展会员制度以包括不同的卷

I have a basic membership system set up using MySQL database with 3 tables, user_id, user_name and user_password. my php code bellow is simple as I am new to php and will develop it further as my knowledge progresses. I am trying to create different rolls at the moment, member, admin and global admin. I am a bit lost on how to progress on from what I have so far. any advice or suggestions will be very much appreciated.

my basic membership code

    <?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>

Summery I have a basic membership system built and i wish to expand it to include Rolls for two level security admin and global admin.

  • 写回答

1条回答 默认 最新

  • dongyi7041 2014-01-05 21:25
    关注

    Well, you can easily add a field in your table, for example

    level
    

    and add a value, for example 1 (basic user) 2 (admin) 3 (global admin).

    When there is an operation which can be done, for example, only by an admin, you just check it like this:

    if ($user_level >= 2) {
    
    echo 'You can do this...';
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大