0

Does anyone know the correct way to set up user levels? Such as if user level == 1 show content for them, then if user level == 2 show content for level 1 and level 2, then if level == 10, which is Admin, show content for level 1,2 - and Admin level.

So far I have this code, but it doesn't work out as I expected:

<?php 

    // if membership level is (1) basic
    if($userMember_level == 1 || $userMember_level == 2 || $adminMember_level == 10){
    content goes here for users of level 1,2 and Admin user


    // if membership level is (2) advanced
    }elseif($userMember_level == 2 || $adminMember_level == 10){
    content goes here for only users of level 2 and Admin user


    // if membership level is (10) admin
    }elseif($adminMember_level == 10){
    content goes here for admin user only, admin can also view levels 1 and 2

    }
?>

What I'm trying to do is allow the Admin to access all levels, level 2 users to access levels 1 and 2, and level 1 users to only access level 1.

  • Levels 10 or Admin to access levels (1,2,Admin)
  • Level 2 users to access levels (1,2)
  • Level 1 users to access level (1)

Thanks for any help.

halfer
  • 19,824
  • 17
  • 99
  • 186
Mike Dawn
  • 73
  • 1
  • 6
  • Read about bits and corresponding values, it will give an idea. This way your will not mix anything, but the number of the level will be limited. It is easier and more flexible to use a separate table with ACL. – Cheery Nov 24 '14 at 01:05
  • Your best bet is probably to have a field in the users table for "role" or something. You can then set a session variable for the admins role type and hide/show content accordingly using jQuery or whatever you prefer. – adanot Nov 24 '14 at 01:05
  • Also, please post what code you have so far. – adanot Nov 24 '14 at 01:05
  • 1
    there are 50 million ways to do this, most of wich could be considered *correct* –  Nov 24 '14 at 01:06
  • Just did a bit of searchin' for ya, and I found this currently on StackOverflow. http://stackoverflow.com/questions/11606960/implement-different-user-level-views-in-php Good luck, sir! – Brandon Palmer Nov 24 '14 at 01:06
  • I actually have my PHP code + tags in on here, I don't know why it isn't showing right now. How do I edit and present my tags? – Mike Dawn Nov 24 '14 at 01:09
  • 1
    Mike, to render code here, select it and click the 'code' button. It will add an indent to the block, which is Markdown format for code. – halfer Nov 24 '14 at 09:12

1 Answers1

1

All I had to do was go to my own MySQL database and inside of the table field that reads:

'membership_level' which is a tinyint of 1

enter (1) for basic user, or (2) for advanced user or (10) for admin.

This allowed me see all user levels, including the admin level.

Thanks everyone for your help.

Mike Dawn
  • 73
  • 1
  • 6