How do I handle user roles effectively?
authentication, php
Solution
you can have tables -
user (user_id, name ...)
permission (perm_id, name, desc)
role (role_id, title)
user_role (user_id, role_id)
user_permission (user_id, perm_id)
role_permission (role_id, perm_id)
This way you can have as many roles in the system as you require, and you have both role level permissions, user level permissions.
Problem
That's kinda vague so here's the meaty stuff: I have seen authentication systems that do one of the following - have a separate role table for each roles, and a separate permissions table, all users in one table - have a separate table for administrators there's a lot that I have missed, I know. But what I'm trying to really ask is: How should I design my database in a website that I have a lot of kinds of users and each with different access? How will I make it so that my script is flexible enough if I decide to add another type of user with another type of permissions? I currently have a User class and am planning to make my Administrator class which extends that User class. Or is that a bit of an overkill when I can have them all in a single class and just assign necessary permissions?