Skip to main content
Participating Frequently
May 23, 2011
Question

Restrict Access to certain users based on if a variable in the SQL database is set to 1

  • May 23, 2011
  • 8 replies
  • 1137 views

Hey guys,
I am quite new to PHP and MySQL and I have a question concerning access  restriction. For a website project I am experimenting with Dreamweaver's  login and restrict access behavior, which works fine. However, on the  website I would like to restrict access for users that only have a 1 set  in the corresponding MySQL database (which means that e.g. each page has a different variable in the database that can be set to 1, which would allow me to personify access beyond the level of the out-of-the box option, where each user can only have one access level). So it is quite similiar to the  out-of-the-box restrict access to page based on user group, but just  depending on another variable in the database.

I guess it can be done with an if condition that checks in the database if the logged in user has a 1 in this variable, and if yes give her/him access if not redirect to another page. However, I could not figure out  how to implement that.

Your help is highly appreciated!

Thanks in advance!

This topic is closed to new replies. Start a new post to keep the conversation going.

8 replies

Participating Frequently
May 24, 2011

Hello guys,

I spend quite some time on the internet reseaching my wish and redefined my need: I would basically like to have the possibility to assign a user multiple access levels. There would be e.g. 10 pages for each I create an access level. Then a user with e.g. access to pages 2 and 8 can only access these two pages. So my basic question is if and if yes how I can assign a user muliple access levels at a time and store these values in the MySQL database.

Thanks a lot for your help!!

Participating Frequently
May 24, 2011

If your access levels are indeed discreet, with no hierarchical relationships, then you need to store a flag for each level that the user has. I would probably create an access level table for this, storing one row for each user/level combination.

Another way...

I usually don't recommend using the MySQL set datatype, but it's probably fine for this application. PHP has functions for accessing values in SET data types.

Participating Frequently
May 24, 2011

Hello bregent, thanks a lot for your answer. I tried to do it with the SET datatype and I gave my testing user 3 access levels: page1, page2, page3. However if I restrict access in Dreamweaver to page2 and/or page3 the access is rejected. It only works with page1... Do I need to change sth. in Dreamweaver's standart restrict access to page behavior?

Thanks in advance!