在2个数据库之间共享用户
我正在用 PHP 开发这个应用程序。该应用程序将包含一个管理区域,其中还包含员工功能。应用程序的另一部分是面向客户的网站。
行政区域有自己的数据库。面向客户的网站也有自己的数据库。
在管理数据库中,我有一个包含用户的表,我还计划实现 RBAC,以便用户可以拥有角色、权限等。
面向客户的网站还允许客户注册,并将其存储在客户网站数据库的用户表中。
我需要的是能够让员工登录客户网站。他们还需要拥有控制可以修改客户网站的哪些部分以及可以更改客户网站数据库中的哪些行的权限。
实现这一点的最佳方法是什么?
干杯:)
I am developing this application in PHP. The application will consist of an adminstration area which will also contain employee functions. The other part of the application is the customer facing website.
The administration area has its own database. The customer facing website also has its own database.
In the administration database, I have a table with users and I also plan to implement RBAC so that users can have roles, permissions and so on.
The customer facing website also allows customers to register and that's stored in a user table in customer website database.
What I need is to be able to have employees logging on at the customer website. They also need to have permissions which controls which parts of the customer website they can modify and which rows in the customer website database they can change.
What's the best way to implement this?
Cheers :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议尽可能合并处理相同概念的表(此处为用户)。
这里的问题是数据访问安全,无论您的数据如何存储(一个或两个表,一个或两个数据库)。
使用MySQL(以及许多其他常见的DBMS),您可以:
创建一个MySQL帐户,该帐户只能访问某些表,只能对其执行一些操作(例如,只能选择),只能访问某些列等。
从 MySQL 帐户中隐藏表并仅授予对某个视图的访问权限此表(过滤列/表结果)。
无论您的数据结构是什么,您都需要检查一些员工数据(登录名、密码、权限等),并且您的代码必须使用具有足够权限的 MySQL 帐户。
因此,我建议您将用户保留在一张表中,添加表来描述角色(员工、客户等),并明智地编码。
请记住分别解决数据库设计和数据访问安全问题。数据访问安全不应该导致您在数据库设计中做出不合逻辑的选择。
I would recommend to always merge, when possible, tables handling the same concept (Users here).
The problem here is the data access security, no matter how your data is stored (one or two tables, one or two databases).
With MySQL (and many other common DBMS), you can :
Create a MySQL account which will have only access to some tables, do only some operations on it (e.g. only SELECT), access only some columns etc.
Hide a table from a MySQL account and give only access to a view on this table (filtering columns/table results).
Whatever is your data structure, you will need to check some employee data (login, password, permissions etc.) and your code will have to use a MySQL account with enough privileges for that.
So I would advise you to keep your users in one table, add tables to describe roles (employee, customer, etc.), and code wisely.
Keep in mind to address separately database design and data access security issues. Data access security should not lead you to illogical choices in database design.
您可以执行以下操作:
作为线程启动器的评论问题。对于两个用户表,您可以使用如下解决方案:
创建新表。例如:global_user_table 字段:
每次用户登录时,让它检查此表并将table_source存储在会话中,以供以后使用.
You can do something like this:
As comment problem from thread starter. For two user tables, you can use solution like this:
create new table. eg: global_user_table with field:
everytime user login, have it check on this table and store table_source on session, for later usages.