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

  • Home
  • SEARCH
  • 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 998523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:12:32+00:00 2026-05-16T07:12:32+00:00

As the title suggests, I’ve inherited a php/MySQL application which has fairly well written

  • 0

As the title suggests, I’ve inherited a php/MySQL application which has fairly well written procedural code, but only has one admin user login. The client naturally wants to split out functionality into different users/roles and ultimately update the application code with best-practice techniques.

For the example of updating someone’s username in the admin section, the original version simply displays a text field prepopulated with the username (code simplified for brevity):

<input type="text" name="username" value="<?= $username; ?>">

The POST is then checked against a regular expression and saved to the database.

I have been asked to look at how to change the existing code so that it can deal with different user ‘roles’ and have quite happily mocked up an example application with tables like user, role, permission, user-role and role-permission to explain how this would work in practice. I just wonder if any of you have any tips on how to write the permissions into the codebase? Is it wise to simply wrap up the existing code either in the template or in a function into something like:

// $access_type can be the result of a function call, an array value, etc.
switch($access_type){
    case 'edit':
        echo '<input type="text" name="username" value="' . $username . '">';
        break;
    case 'readonly':
        echo $username;
        break;
    case NULL:
    default:
        // Don't display anything.
}

My question is how well does this scale with larger chunks of code? There are a couple of ‘interactive features’ which use quite a lot of HTML & JavaScript to POST back several values at once. We’d effectively have a seperate version of this custom control for each role. Sticking each version into a switch smells a bit (whether inline code or included as a separate file)… Similarly, on the backend, the script to process the POST would have several versions depending on the role.

I know there must be a hundred ways to do this, but what have other people done in the past? If you have some insight, could you demonstrate it in a procedural style as there is no OO to be seen in this project! Thanks!

  • 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-16T07:12:33+00:00Added an answer on May 16, 2026 at 7:12 am

    You can use something like:

    interface User {
        /* stores several roles */
        /**
         * Combines the permissions of the several roles
         * of the user and returns the result.
         * @return Permission */
        function getPermission($key);
    }
    interface Role {
        /* stores several permissions */
        /* if there's no record of this kind of this
         * particular permission, return an empty one */
        /** @return Permission */
        function getPermission($key);
    }
    interface Permission {
        /** @return Permission */
        function combine(array $permissions);
        /** @return bool */
        function canEdit();
        function canRead();
    }
    

    and then just do:

    /* user factory takes care of creating the instances and
     * wiring them together */
    $u = UserFactory::loadCurrentUser();
    if ($u->getPermission('admin_page')->canWrite()) {
        //...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title suggests im working with a Core Data Application which gets filled
As the title suggests, I am having trouble maintaining my code on postback. I
As the title suggests I have two models Products And Orders which are actually
As the title suggests, I'm working on a site written in python and it
Well, as the title suggests: I have a storyboard and I want it's animation
As the title suggests, we have a Java (Swing) desktop application, and we'd like
As the title suggests, I was wondering how one decides which protocol to implement.
As the title suggests, is there any way to read the machine code instructions
As the title suggests, I'm trying to write some C# code to interop with
As the title suggests I cannot log into my CakePHP application with IE. Same

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.