Basically, the user management involves 2 database tables, say, tb_users and tb_groups. tb_users contains user_id, user_name, user_password, group_id and other information.
tb_groups contains group_id, group_name and some authority like: auth_view, auth_post, auth_upload,...
Whenever a user is logged and try to use a service, the php code will check the database to see if he have right or not.
The following is a proposal function to it conveniently
function check_auth($user_id,$auth)
////For example check_auth('upload')
{
global $_CONNECTION;
$group_id=get_group($user_id);
$field="auth_$auth";
$sql="SELECT $field
FROM ".TB_GROUPS."
WHERE group_id=$group_id";
if ($result=mysql_query($sql,$_CONNECTION))
{
if (mysql_num_rows($result))
{
return mysql_result($result,0,$field);
}
else
{
return 0;
}
}
else
{
return 0;
}
}//end function
If you have other ideas, please share ;)
No comments:
Post a Comment