Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6380757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:18:32+00:00 2026-05-25T02:18:32+00:00

Here is the table of user rights Post Guest User Admin Create N Y

  • 0

Here is the table of user rights

Post
        Guest User                      Admin 
Create    N     Y                         Y
Read      Y     Y                         Y
Update    N   Their own post ONLY        All
Delete    N     N (yes, user can't del)   Y

And here is the situation. I am thinking putting all the validating user rights in one single class to handle. And all the action have a defined name, for example: create_post, read_post. Also, have a user_role to pass in, let say: role_guest, role_user. And the validation class do all the magic. What do you think of this design? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:18:33+00:00Added an answer on May 25, 2026 at 2:18 am

    You could use a bitmask.

    If all your permissions are (or can be generalised to) a set of yes/no conditions, it’s quite easy.

    In your example, you have Create, Read, Update and Delete. That’s 4 bits, so you need a 4-bit number to store permissions. (0000 to 1111 in binary = 0 to 15 in decimal)

    Someone who can only read would have permissions 0100 (4 in decimal), and someone who can create/read/update would have persmissions 1110 (14 in decimal). Administrators who have full access would have persmissions 1111 (15 in decimal).

    The way you would check these in PHP would be with the bitwise OR operator |.

    For example

    // you could write a function getUserPermission($strUsername)
    // which returns a permission number, say 10 (1010 in binary)
    // which means he/she can create/update but not read/delete
    $userPermissions = getUserPermission("TedWong");
    
    $permissionCreate = 8; // 1000;
    $permissionRead   = 4; // 0100;
    $permissionUpdate = 2; // 0010;
    $permissionDelete = 1; // 0001;
    
    if ($userPermissions | $permissionCreate)
    {
      //user has permission to create
    }
    
    if ($userPermissions | $permissionRead)
    {
      //User has permission to read
    }
    
    if (!($userPermissions | $permissionDelete))
    {
      //User doesn't have permission to delete
    }
    
    if ($userPermissions | $permissionUpdate &&
        $userPermissions | $permissionCreate)
    {
      //User has permission to create and update.
    }
    

    If you want more permissions, you just need to introduce more bits.

    As for your update all posts/delete own posts in your example, I would have a 5-bit permission structure: Create, Read, Delete, UpdateOwn, UpdateAll.

    You can have many permissions, but would be limited by the data structure storing them. For example, if you are storing the permission mask in a 32-bit integer, then you can only have up to 32 permissions.

    here is a full list of 4-bit permissions for your example:

    0000 //  0: No Permissions
    0001 //  1: Delete
    0010 //  2: Update
    0011 //  3: Delete + Update
    0100 //  4: Read
    0101 //  5: Read + Delete
    0110 //  6: Read + Update
    0111 //  7: Read + Delete + Update
    1000 //  8: Create
    1001 //  9: Create + Delete
    1010 // 10: Create + Update
    1011 // 11: Create + Delete + Update
    1100 // 12: Create + Read
    1101 // 13: Create + Read + Delete
    1110 // 14: Create + Read + Update
    1111 // 15: Create + Read + Delete + Update
    

    So that means the INTEGER 6 (which in BINARY is equal to 0110) gives permissions Read/Update but not Create/Delete. In the same way each integer has a set of permissions associated with it. You can store up to as many permissions in the integer as many bits there are that represent that integer (usually 32).

    So you can see that with a 4-bit integer (decimal numbers 0 to 15) can give you 4 yes/no permissions. If you use a 32-but integer then you can have up to 32 yes/no permissions.

    Check the PHP documentation on how to determine the maximum size of your integers. (It depends on the platform you’re running your PHP parser on). I think generally speaking a 32-bit system/OS will allow for 32-bit integers, and 64-bit system/OS will allow for 64-bit integers.

    Check these other threads on SO for discussions on pros/cons of using bitmasks vs other methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is my 3 tables: table 1 -- stores user information and it has
Here's the scenario: I have 2 tables: CREATE TABLE dbo.API_User ( id int NOT
Replaces Question: Update multiple rows into SQL table Here's a Code Snippet to update
Here's my table: CREATE TABLE `alums_alumphoto` ( `id` int(11) NOT NULL auto_increment, `alum_id` int(11)
CREATE TABLE #Report( Cell int, CellValue double) Error here DECLARE @Report TABLE ( Cell
Background First of all, much gratitude to atebits for their very informative blog post
I'm working on a profile page, where a registered user can update their information.
I am following Steven Sanderson's blog post here to create an editable and variable
Here is my table in the dataset: SELECT tag_work_field.* FROM tag_work_field I created this
Here is my table: id int(11) name varchar(255) description text highest_bidder int(11) value varchar(255)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.