play_ Posted March 21, 2009 Share Posted March 21, 2009 Tiny security question. There are 3 levels of users. Normal users, moderator and Admins. I the midst of the `members` table, is this field: `user_level` Now, when you login, you get all your sessions started, including $_SESSION['user_level']. So if you're admin, your $_SESSION'user_level'] will be 1. If you're a moderator, your $_SESSION['user_level'] will be 5 If you're a normal user, your $_SESSION['user_level'] will be 10 Now, to restrict access to certain pages... I have this method: function restricted() { session_start(); $args = func_get_args(); if( in_array($_SESSION['user_level'], $args) ) { header("Location: /index.php"); } } So on the page, i can restrict access by passing ints of the level of the users i want the page accessible too. For example: $s->restricted(1); // admins only $s->restricted(1, 5); // admins and mods only It's simple, but i don't really see a flaw with it? If anyone sees anything wrong, please let me know so I stop using it. Link to comment https://forums.phpfreaks.com/topic/150483-is-this-safe/ Share on other sites More sharing options...
play_ Posted March 21, 2009 Author Share Posted March 21, 2009 correction: if( !in_array($_SESSION['user_level'], $args) ) { Link to comment https://forums.phpfreaks.com/topic/150483-is-this-safe/#findComment-790380 Share on other sites More sharing options...
Mchl Posted March 21, 2009 Share Posted March 21, 2009 Seems fine to me. I used similar system myself once. Link to comment https://forums.phpfreaks.com/topic/150483-is-this-safe/#findComment-790387 Share on other sites More sharing options...
play_ Posted March 21, 2009 Author Share Posted March 21, 2009 Yea.. just making sure. I am thinking of going a step further. I wanna make it so i can pass one int as argument. For example, all the pages the mods can see, the admin can see too, since admins are higher-ups in the system. So instead of doing $s->restricted(1, 5); // admins and mods I would do: $s->restricted(5); // admins and mods because 1 comes before 5, it would automatically be allowed in. Link to comment https://forums.phpfreaks.com/topic/150483-is-this-safe/#findComment-790399 Share on other sites More sharing options...
xylex Posted March 21, 2009 Share Posted March 21, 2009 Make sure you have a default value if you do that if the session value isn't set, since (int) NULL is also < 5 Link to comment https://forums.phpfreaks.com/topic/150483-is-this-safe/#findComment-790404 Share on other sites More sharing options...
play_ Posted March 21, 2009 Author Share Posted March 21, 2009 Make sure you have a default value if you do that if the session value isn't set, since (int) NULL is also < 5 Yep. Thanks. Link to comment https://forums.phpfreaks.com/topic/150483-is-this-safe/#findComment-790407 Share on other sites More sharing options...
Philip Posted March 21, 2009 Share Posted March 21, 2009 I also do a similar setup, in reverse. Super admins get 255 Admins get 200 Mods 100 Normal users 1+ Banned 0 Then on permissions: if($user >= 100) // mod area if($user >= 200) // admin area Link to comment https://forums.phpfreaks.com/topic/150483-is-this-safe/#findComment-790419 Share on other sites More sharing options...
laffin Posted March 21, 2009 Share Posted March 21, 2009 Yes, thats the system Im used to as well KingPhillip. But I over the years, i got tired of the hierachy system. And now a days I use a flag system instead. Which seems to work out better for me, since I want a flexible and be able to serve groups within the community as well. With the hierarchy system, if create 3 groups (groupA, groupB, groupC). u will end up adding code for each group to test for the group affiliation. than it just gets complicated if u add a moderator to that group. as now u have to create yet another user type. so now a days i prefer the flag system. Where I can define different areas of the system, and give access according to wut I want. I believe best way to see the flag system, is by looking at several apps that have it in place. such as TikiWiki. Where U can define a default set of flags for different user groups, but still allows u to assign an individual overriding flags. Anyways good luck Link to comment https://forums.phpfreaks.com/topic/150483-is-this-safe/#findComment-790444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.