发展会员制,包括不同的卷 [英] develop membership system to include different rolls
问题描述
我有一个基本的会员系统,使用MySQL数据库设置3个表,user_id,user_name和user_password。
我的php代码下面很简单,因为我是新的php和将进一步发展,因为我的知识进步。
我正在尝试创建不同的卷,成员,管理员和全局管理员。我有点失去了如何进步从我迄今为止。
$ b
我的基本会员密码 b
<?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)或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 ='对不起,用户名/密码错误';
}
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 =postname =formLoginid =formLogin>
< table width =400border =1align =centercellpadding =2cellspacing =2>
< tr>
< td width =150>用户名< / td>
< td>< input name =user_nametype =textid =user_name>< / td>
< / tr>
< tr>
< td width =150>密码< / td>
< td>< input name =user_passwordtype =passwordid =user_password>< / td>
< / tr>
< tr>
< td width =150>< / td>
< td>< input name =btnLogintype =submitid =btnLoginvalue =登录>< / td&
< / tr>
< / table>
< / form>
< / body>
< / html>
夏季 一个基本的会员制度建立,我想扩展它包括Rolls两级安全管理和全局管理。
您可以轻松地在表中添加字段,例如
level
pre>
并添加一个值,例如1(基本用户)2(管理员)3(全局管理员)。
当有一个操作可以完成,例如只有一个管理员,你只需这样检查:
if($ user_level> = 2){
echo'你可以这样做...';
}
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.
解决方案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...'; }
这篇关于发展会员制,包括不同的卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!