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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:01:11+00:00 2026-05-31T02:01:11+00:00

I currently have an array that hold information that a user can do. I

  • 0

I currently have an array that hold information that a user can do. I currently use one instance of this in a dropdown menu which is very nice. What I want to do now is only include particular items if they have access to it. So say if $user_access=2 then they can do Download->small_image but not Download->large_image. I would like to be able to assign what the default access for each item in the array…even the key. So I can say a user access is 0 so they shouldn’t display “Download” at all.

I thought maybe putting the access integers for each in an object. So $access->download->small_image = 2; and then I could check one by one if an access level is greater than or equal to it and add it to the array? I’m actually not sure how I would do the loop and build up the array correctly. Another way…maybe put the access value in the actual array somehow? Any ideas would be great.

$var = array("Download" =>                                                
                   array("small_image" => "ajax_load",                         
                         "large_image" => "/master.php"),                       
                   "Page" =>                                                    
                   array("Edit" => "edit.php",                                  
                         "View" => "view.php",                                  
                         "Stuff" => "stuff.php")                                
                   );      
  • 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-31T02:01:12+00:00Added an answer on May 31, 2026 at 2:01 am

    Access control is always a vague question, because there’s an unlimited amount of options. It sounds like you would be happy with an access array, IE:

    array(
        0 => "root",
        10 => "Group1",
        20 => "Group2"
    );
    

    I would probably use an array for your ACL (Access Control List) also:

    $ACL = array(
        "Download" => array(
            "Small_Image" => 10,
            "Large_Image" => 20
        ),
        "Page" => array(
            "Edit" => 0,
            "View" => 10
        )
    );
    

    Then call a function to authorize:

    function checkACL($option, $arg, $lvl)
    {
        if( $ACL[$option][$arg] >= $lvl )
            return true;
        else
            return false;
    };
    
    $userLevel = 10;
    if( checkACL("Page", "Edit", $userLevel) ) {
        /*
         * Display Edit page here.
         */
    } else {
        /*
         * Display "Not authorized" or redirect to a different page.
         */
    }
    

    Sorry, hope that didn’t go off topic too much.
    But you can adapt that to display your menu. I’m assuming you have a login system already of coarse 🙂

    if( checkACL("Download", "Small_Image", $userLevel) ) 
        echo '<a href="'.$var['Download']['Small_Image'].'">Small Image</a>';
    

    Edit:

    $var = array(
        "download.small_image" => array(
            "id"    => 1001,
            "file"  => "/img/blue.png",
            "width" => "100px",
            "height"=> "100px",
            "accessLevel"=> 20
        ),
        "page.listUsers" => array(
            "id"   => 1011,
            "file" => "/pages/list.php",
            "accessLevel" => 10
        )
    );
    

    So it works in the same principle, but all the information is centralized.
    What I would do if I wasn’t using a database is store it as a json file.
    You don’t want to hard code it into a php file, you want it easily modifiable.

    // This will load your permissions into $var
    $var = json_decode(file_get_contents("/acl.json"));
    
    // If you design a page to modify permissions, you can save the file with this.
    file_put_contents("/acl.json", json_encode($var));
    
    // json is simple, it's basically just { "key" : "val" }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined an array that can hold 10 elements. I have add 3
Now I currently have an array that contains 120 pairs. For example: [[1, 12],
I currently have a model that creates an array and returns it using the
I currently have an array that's outputting as follows: Array ( [events_response] => Array
I currently have a large array of floats that I process in my OpenCL
I currently have the dynamic array: char *myData[500][10]; //myData is the name of an
So, I have a class with an array inside. Currently, my strategy for enumerating
I currently have an MS Access application that connects to a PostgreSQL database via
We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
I have a (C#) genetic program that uses financial time-series data and it's currently

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.