Archive for February, 2009

Application Access Levels with PHP

Saturday, February 28th, 2009

Hello all

This week we got a job in to write an intranet site for a large Insurance company in the UK.

It had 60 or so applications that needed writing with access to each being given on a per user basis.

So for example user “A” could see applications 1 and 3, and user B could only use application 2.

So how do you do this easily?

We started off having a link table, it had User ‘A’ mapped to application 1 and so on. Which is ok but they have 5000+ staff and 60 applications so that would be a table with 300,000 rows in it, which in its self in MySql is nothing really, it just seemed excessive.

What we came up with is a bitwise solution so each application had a bit assigned to it. So if you remember your binary “0 1 2 4” etc. Each application was assigned a binary number, so application 1 was “1” in binary, application 2 was “10” ,application 3 was “100” and so on

So if a user as an access level of 7, that would translate in to a binary number of 111 so they could access application 1, 2 and 3. If a user had an access level of 4 for example they could only access application 3.

Binary (Base 2) Application
0 Superuser
1 Application 1
2 Application 2
4 Application 3
8 Application 4

We will post the class over the next few weeks if any body else wants to use it.

Happy coding