• 0

[PHP] Creating a 'rank system'


Question

I'm currently working on a CMS system for my latest project; the area I'm confused in is creating a ranking system.

Currently, I have an array which stores the user ranks


$rank = array (

'0' => 'user',
'1' => 'moderator',
'2' => 'administrator',
'3' => 'owner'

);
[/CODE]

What I want to do, is determine the rank of the user, then create an array that sets the ranking for the user.

For example, if the user is an administrator, their session array would look like the following

[CODE]
$_SESSION['rank'] = array("administrator","moderator","user");
[/CODE]

So I can check then check the users rank with the in_array function.

Hopefully I explained the above okay, if you need anymore information please ask.

Many thanks,

Matthew.

Link to comment
https://www.neowin.net/forum/topic/1051357-php-creating-a-rank-system/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

If you are working on a CMS system i would suggest making this inside a DB table.

This way you can edit/add ranks by using an Admin Panel then in the Users table in the DB have a field for Rank where each user will get his own rank.

After that you can check the rank of the user in the Users DB and set the permissions from there.

That's my suggestion.

  • 0

Okay, I've created an area within my database now, and I'm going to create an array which I can check these ranks against.

How would I set the user permissions from here?

Basically, how would I check what rank the user is, and then set a $_SESSION array setting their ranks as administrator but also listing 'user' and 'moderator' within these ranks?

  • 0

You probably have a DB Table for Users right? Where you set users info like username, password, email and other stuff.

In that table set another field names Rank or something and in that field you need to set the rank of the user. Set this fields default to like 1, so 1 = simple member rank.

Then basically any place you want to set access only for some of the members you can do it with IF....

  • 0

Hmm, I'm not sure if you understand fully what I want to do..

I have a user table, yes, and I have a rank section in there where I can set the rank ID.

From here, I would like to select the rank ID and the group which that rank refers to,

for example, group 1 refers to user, group 2 moderator etc.

From here, I would like to set the user ranks in an array, so..

If the user rank is 1, the array will be set as array("user");

If the user rank is 2, the array will be set as array("user","moderator");

and so on, from here I will detect the user ranks as...

if(in_array($rank, "user") { echo 'Welcome, user'; }

How would I go about that? It's the area where, if the users rank is 2, their array will be set as 1,2 that I am confused with.

  • 0

Well, maybe it's just me but why would you need an array for this?

Let's say:

1 = Member

2 = Moderator

3 = Admin

Now everyone should see whatever the Member can see so it's easy.

Now whatever the mod can see the Admin should see as well so you can use - if (RANK > 1) { }

If you need to set something only for the Admin then you user - if (RANK == 3) { }

Maybe i'm missing something but i would do it this way instead of messing with Arrays, it will give you exactly the same thing.....

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • It's Intel-based, but I configured one of these yesterday with a Snapdragon X processor and found that it heats up just as much as Intel processors. There's no point in using a Snapdragon X processor unless it's fanless, like the Snapdragon 8cx.
    • Good stuff Brave. Hopefully MS respects user choice with this. They don't have a great track record but time will tell.
    • Yes. A search on Bing would have explained it.
    • As someone who regularly has to go through the OOBE for the Mini PCs I review, I can confirm that this "Windows Update failed" thing happens even on newly installed systems. I had it last week until I left it on overnight and only then did it somehow magically fix itself and applied the update, this was after wasting a full day of resetting, clearing Windows Update cache (following Microsoft recommendations). Microsoft needs to stop this BS of releasing (at best) beta quality features and updates. They need to go back to using Patch Tuesday for bugs and security fixes, and annual Service Packs to introduce fully tested new features into the OS. The 21H1, 21H2, 22H2, 23H2, 24H2 style updates are just a poor excuse of rolled up features released up to and in between these updates, and even then some of the announced features don't get enabled for end users? What is preventing my 24H2 AMD 9950X3D, X870E system from displaying the Phone Link panel in the Start menu, for example?
    • RIP Prince... for over 50 years you entertained us, brought us musicians that wowed the masses... you brought us into your home, your world and your loving insanity for life itself. You'll never be truly gone, because you'll be with us for the rest of our own lives.
  • Recent Achievements

    • Week One Done
      SmileWorks Dental earned a badge
      Week One Done
    • Community Regular
      vZeroG went up a rank
      Community Regular
    • Collaborator
      Snake Doc earned a badge
      Collaborator
    • Week One Done
      Snake Doc earned a badge
      Week One Done
    • One Month Later
      Johnny Mrkvička earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      583
    2. 2
      Michael Scrip
      199
    3. 3
      ATLien_0
      196
    4. 4
      +FloatingFatMan
      129
    5. 5
      Xenon
      123
  • Tell a friend

    Love Neowin? Tell a friend!