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 6647413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:32:05+00:00 2026-05-26T00:32:05+00:00

I have about 15-20 permission settings that are loaded when a user logs in.

  • 0

I have about 15-20 permission settings that are loaded when a user logs in. These are each stored as a session with a value of 1 or 0.

I’m wondering, would it be better to have one session like $_SESSION['permissions'] with a value of: dothis:0,dothat:1,doanother:1, etc. (one large string) which I can explode and seperate later on with PHP, or would it be best to have all these as separate sessions with just a value of 1 or 0?

  • 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-26T00:32:05+00:00Added an answer on May 26, 2026 at 12:32 am

    Rather than a string to parse, store them as an array in $_SESSION. This makes it much easier to modify individual permissions without having to do piles of string operations.

    session_start();
    $_SESSION['permissions'] = array();
    $_SESSION['permissions']['dothis'] = TRUE;
    $_SESSION['permissions']['dothat'] = FALSE;
    $_SESSION['permissions']['doanother'] = TRUE;
    

    Addendum

    You might have figured this out already, but I thought I would add that it is easiest to interact with these via a few tiny functions. These will save a lot of typing (and typing errors), and make sure the values all end up as booleans.

    function grant($permission) {
      $_SESSION['permissions'][$permission] = TRUE;
    }
    function revoke($permission) {
      $_SESSION['permissions'][$permission] = FALSE;
    }
    // Test if the user is allowed to do $permission
    // FALSE if the permission isn't set
    function user_can($permission) {
      return isset($_SESSION['permissions'][$permission]) ? $_SESSION['permissions'][$permission] : FALSE;
    }
    

    The you can just call them as:

    grant('dothis');
    revoke('dothat');
    if (user_can('doanother')) {
       // congratulations you're allowed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few questions about Core Location. 1) Should the user refuse permission
I have about 20 grid views that I have to create. All of them
i have about 60 fragments ListFragment , now i use each Listfragment with another
I have about 8 entities that all have a one to one relationship with
i have about 20 possible exception messages that i want thrown when an error
I have about 10 drop down list controls that get populated. Instead of copying/pasting
I have a question about User-Defined Table Types in SQL Server 2008. For the
I have a user that is currently running my Winforms app on Win7. My
I have an ASP.NET website (in C#) that takes in user data and then
I have a database and I want to allow users that I give permission,

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.