Jump to content

Is this safe?


play_

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.