Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
May 23, 2011 May 23, 2011

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!

TOPICS
Server side applications
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2011 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!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2011 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2011 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2011 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2011 May 24, 2011

Yes, you will need to modify the DW server behavior. As far as I know, it doesn't natively handle multiple levels per user.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 25, 2011 May 25, 2011

Hello bregent! Thanks for your answer. I tried to find tutorials on how to modify the native DW behavior that it can handle muliple access levels per user. Unfortunately I was not very successful. Can you maybe help me out here? Help is highly appreciated!! Thx!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2011 May 25, 2011

Sorry, I'm a VBScript guy and don't know enough about PHP to give coding advice. You may want to start a new thread with a more specific topic.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 25, 2011 May 25, 2011
LATEST

Ok, thanks a lot for your help! I will follow your advice and open a new thread.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines