- Joined
- Apr 30, 2011
- Messages
- 241
- Reaction score
- 23
At the moment I am working on a large project with my friend, and I am currently creating a 'user rank' system, which determines what actions a user can take when they are logged in, for example a moderator will be able to delete and manage posts, whereas a user hasn't.
Earlier today, I created the following basic system
Which seemed to work quite well.
What I am wanting to do now, is advance the system a little bit. I would like to make it so if a users rank is an administrator, the $rank variable will be set to have all the ranks.
For example...
I was wondering if there is a better way to set the ranks, instead of having several different if methods to set the ranking.
Hopefully I've explained it well,
Thanks!
Oh, I forgot to say that I was also looking to store the data in an array, so for an owner, the rank array would look like the following
I will then set permissions like the following
Earlier today, I created the following basic system
PHP:
public static function get_rank($id) {
$rank = array (
'0' => 'banned',
'1' => 'user',
'2' => 'moderator',
'3' => 'administrator',
'4' => 'owner'
);
$qry = mysql_query("SELECT * FROM `users` WHERE `ID`='$id'");
$ass = mysql_fetch_assoc($qry);
$rank = $rank[ $ass['rank'] ];
return $rank;
}
Which seemed to work quite well.
What I am wanting to do now, is advance the system a little bit. I would like to make it so if a users rank is an administrator, the $rank variable will be set to have all the ranks.
For example...
PHP:
if($rank=4) {
$rank = user,moderator,administrator,owner;
}
I was wondering if there is a better way to set the ranks, instead of having several different if methods to set the ranking.
Hopefully I've explained it well,
Thanks!
Oh, I forgot to say that I was also looking to store the data in an array, so for an owner, the rank array would look like the following
PHP:
$rank = array("user","moderator","administrator","owner");
I will then set permissions like the following
PHP:
if(in_array("user",$rank)) echo 'Welcome'

