Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 12-17-2004, 05:57 PM   #1 (permalink)
Rafkin
Registered User
 
Rafkin's Avatar
 
Join Date: Mar 2004
Posts: 20
Rafkin is on a distinguished road
Database layout - opinions?

I am working on a php script. I still need to do the php part, but when I get that far, I'll take this to the php section of the board. For right now, though, I'm trying to figgure out the best database layout to use.

I've not really done a complex database layout before, though I have seen one done for another site, in wich I was able to help with the coding and figguring out way that site was going to work. As such, I managed to come up with this layout for what I need, but lack confidence in my own work, and am asking for suggestions or help in making sure I do this right.

If I can get this script to working, I will be making it available, for free, via several php script archives. So flexibility, and portability are issues I am dealing with here. (unless I just simply can't make it flexible or portable, at wich point it'll be just for my personal use, though I'd really like to be able to share it.)

First off, let me explain what the script is. It's sort of a session handling, authorization, user management script. Basically, It will let users register to the web site (I'll get into the email verification etc. when I go to the php forumn), and once registered, be automatically assigned to a user group.

This script will use both user groups and flags, to determine access to different parts or features of the web site. For this use, a group will be nothing more than a bunch of pre-set flags, so that one can work with groups of people easily. The admin would then be able to set private flags per person to overwrite any group flags.

Access to a page or feature will need to check for the flag first on the users level, wich can be either True (allowed), False (not allowed) or non-existant. If non-existant, it should then check the user's group, and if non-existant there, go to the default.

(in all actuality, I'm probably going to have it fill in defaults into an associative array first, then overwrite with group flags, then overwrite again with user flags.)

The database schema I have currently is this:

Users
Code:
User ID - Personal user ID number
Group ID - Group the user belongs to
User Name - Self explanitory
User Pass - encrypted
User Email - Self explanitory
Last Visited - For last visited line
LoginID - Sort of an extended sessionID. I've used this before.
User Groups
Code:
Group ID - unique group ID
Group Name - Self explanitory
Group Desc - Short description of the group
Flag Groups - This is to group like flags togeather when editing. eg: calendar editing, writting, and viewing flags would all go under calendar group. It's just for convenience of the admin.
Code:
Flag Group ID - unique ID
Flag Group Name - Self explanitory
Flag Group Desc - Short descriptioin of the flag group
Flags
Code:
Flag ID - All these freakin ID's. Sheesh!
Flag Group ID - Wich flag group it belongs to.
Flag Name - Everything has got to have a name.
Flag Desc - Short description of the flag.
Default - True or False. This is where the default value will be set.
And finally

Flagsets - still looking for a better name to call this. This is where I tie users and groups to flags.
Code:
Line ID - Will seldom get used, except to edit, or delete a setting.
User or Group ID - The ID for the user or group this flag is setting. User ID's start with U, Group ID's start with G
Flag ID - The flag being set
Value - True or False.
Will this be sufficient? should I do anything different for optimization? I am wondering if I should set some of the user details to a different table, in case I want to add more fields to keep track of per user?

Thanks in advance for any opinions or idea's.
Rafkin is offline   Reply With Quote
Old 12-18-2004, 06:42 AM   #2 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
What about a user that is a member of multiple groups?

Is that where these flags come in?

-r
idx is offline   Reply With Quote
Old 12-18-2004, 08:31 AM   #3 (permalink)
Rafkin
Registered User
 
Rafkin's Avatar
 
Join Date: Mar 2004
Posts: 20
Rafkin is on a distinguished road
What I had thought was, to have each user a member of only one group. Again, the group is just a set of pre-set flags, to make managing more then one person at a time easy. The difficulty I see in having a member part of more than one group would be, conflicting flags. If one group is denide access to one flag, while another is allowed access. wich do I go with?

That is why flags are set on three levels. Default, Group, and User.

When access to a flag is checked it should check the user level first, and if not there, check the group level, and if not there again, go to default. At each level the flag could be set as True, or False (allowed or not allowed). Upon finding either one, the search would stop at that point.

I'll even put in an option for the admin, when switching a user from one group to another, to clear all user flags or leave them in, at his discretion.

I've decided to go with the schema i've got laid out above, may change it as I go. Now I'm gonna try to figgure out all of the php scripting needed to use the tables effectively.
Rafkin is offline   Reply With Quote
Old 12-18-2004, 06:42 PM   #4 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Sounds like more trouble than it's worth. There's always phpGACL and seagull to use unless you just want to write it.


The way I've structured things in the past is that each public function is defined group access. eg: So only members of "foo_add" can execute it. All users are part of the "users" group, but they can also be assigned to others as well.

Most of my applications required something more fine grained, so I ended up having more validation code anyway. (eg: user can excute the delete function in the FAQ class, but only on items they created or were specifically assigned to..)

-r
idx is offline   Reply With Quote
Old 12-29-2004, 07:36 AM   #5 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
I forgot to mention LiveUser as well. Looks pretty slick and doesn't seem to be as difficult as phpGACL.

-r
idx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Real Estate RMLS Database Redline PHP 11 11-17-2005 06:20 AM
Can't see MySql database records in Mozilla monicao PHP 3 05-02-2004 05:19 PM
Methods of moving a database... DarkTwilkitri PHP 8 11-19-2003 05:02 AM
Database Users Keen on Linux 2.6 Kernel sde Linux / BSD / OS X 0 05-19-2003 02:01 PM


All times are GMT -8. The time now is 02:08 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting