2

I am building a website in PHP & mySQL. It has frontend and backend capabilities. Only admin can enter the backend by means of username and password. Now if the admin wants to add other sub-admins to the website, he could do so. By this method, a sub-admin will be able to login and perform all actions that the original admin is able to do.

WHAT I WANT TO DO:

I want to restrict the access of the sub-admins at my choice and assign them permissions so that they are able to access only certain portions of the admin panel.

EXAMPLE OF THE FEATURE THAT I AM TALKING ABOUT:

Consider that I have the following links accessible by original admin. 1. Add articles 2. Approve articles 3. Delete Articles 4. Add User 5. Edit user 6. Delete User 7. Change site settings 8. View Financial info 9. Mail center

If I do not set any permissions, then all sub-admins will be able to access all of above links. Say I create 2 sub-admins 'David' and 'Bob'.

Now I want David to access only the following desired sections of the backend:

  1. Add articles, 4. Add User, 7. Change site settings

Now I want Bob to access only the following desired sections of the backend:

  1. Add articles, 2. Approve articles, 3. Delete Articles, 4. Add User, 9. Mail center

I, being the original admin, should be able to access all sections whereas, David and Bob, should be able to see & access only the links and pages (or functionality) that have been assigned to them. I don't have a clue as to how to do this. Also, for example, if I want to restrict a sub-admin to access only 'Add articles' page, then I also want him to access the page that it posts to (considering that the input is on Add articles page) add_articles_next.php page. Also note that 'add_articles_next.php page' does not appear anywhere in the list of links. It is merely a page that is posted to from the page to which the sub-admin has access.

I understand that there is no way for the system to know that unless I explicitly specify it, but yes, that's my question. How to do it? I am not a object oriented person, so PHP code using functions will be great for me.

OTHER LIVE EXAMPLES OF THE FEATURE THAT I AM TALKING ABOUT:

I came across a feature while researching this topic. Click here to visit it. This looks like somewhat similar feature.

Thank you all in advance for any code that you can give me.

4

1 回答 1

5

之前在 SO 上已经多次询问过这个问题。要搜索的关键字是访问控制列表 (ACL)。针对 ACL 的最著名的 PHP 解决方案之一是Zend_ACL。它非常通用,应该使您能够根据需要对其进行自定义。

编辑您对面向对象库的评论:

找到一个非面向对象的 ACL 解决方案将非常非常困难,因为市场上很少有优秀的 PHP ACL(Zend 是我所知道的唯一一个,真的)而且大多数现代应用程序都需要更多或较少面向对象的方法。但别担心,看看教程。我认为在面向函数的应用程序中使用 Zend_Acl 不会有任何问题。您将需要通过 OOP 与 ACL 对话,但这很容易。我认为您不必对应用程序进行太多更改。试一试,总的来说,基本的 OOP 并不难学。只需阅读 PHP 手册中的“类和对象”一章即可。

于 2009-12-27T20:34:21.370 回答