英文:
How to retrieve user permissions? (crud system)
问题
我找不到任何好的方法来获取我的用户权限。
我使用了多个SQL查询来根据他们的角色获取用户数据,但我不喜欢每次用户点击某物时都要询问权限的想法...但我也不喜欢从SQL获取所有权限并将其全部设置在 "session" 中的想法。
至少有12列(权限)。我使用4个表,users、users_role、roles和最后的permissions。
//...
$permissions = sqlSelect($conn, '
SELECT * FROM permissions
INNER JOIN roles
ON permissions.role_id = roles.id
INNER JOIN users_role
ON permissions.role_id = users_role.role_id
WHERE users_role.user_id = ?', 'i', $row['id']);
$user_permissions = array();
while ($permission_row = $permissions->fetch_assoc()) {
unset($permission_row['id_role']);
$user_permissions[] = $permission_row;
}
$_SESSION['logged'] = true;
$_SESSION['user_permissions'] = $user_permissions;
//...
英文:
I can't find any good method to get my user's permissions
I used multiple SQL queries to get the user data based on their role but I don't like the idea of asking the permission every time the user clicks on something... but I also dislike the idea of getting all the permissions from SQL and set it all in the "session"
There are at least 12 columns (permissions). I use 4 tables, users, users_role, roles and finally permissions
//...
$permissions = sqlSelect($conn, '
SELECT * FROM permissions
INNER JOIN roles
ON permissions.role_id = roles.id
INNER JOIN users_role
ON permissions.role_id = users_role.role_id
WHERE users_role.user_id = ?', 'i', $row['id']);
$user_permissions = array();
while ($permission_row = $permissions->fetch_assoc()) {
unset($permission_row['id_role']);
$user_permissions[] = $permission_row;
}
$_SESSION['logged'] = true;
$_SESSION['user_permissions'] = $user_permissions;
//...
答案1
得分: 0
你需要使用会话。
首先从MySQL中检索权限并将它们存储在会话中。
然后使用会话来检查权限。
最后,当用户退出登录时,清除该会话。
英文:
you need to use session.
first retrieve permissions from mysql and store them in a session.
then use session to check permissions.
and finally when a user logged out. clear this session.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论