[英]checking user role and restriction for user
Let suppose i'm working an application ( PHP & MYSQL )
假设我正在处理一个应用程序
( PHP & MYSQL )
and in this app has an user table
for storing user information. 并且在此应用中具有用于存储用户信息的
user table
。
Users table column name
用户
table column name
id user_name password role
There are some user role for accessing application. 访问应用程序有一些用户角色。
i) All
ii) Read only
iii) Edit
iv) Entery only
v) Etc.
I'was store there role separated with ,
now i'm not understanding how to check user role and code for that application... 我将角色存储在其中
,
现在我不了解如何检查该应用程序的用户角色和代码...
I'm trying something like that.. 我正在尝试类似的东西。
$roles = implode(“.”,$_SESSION[‘user_role’]);
If( array_key_exist(“all”,$roles) && array_key_exist(“edit”,$roles) ){
// do some stuff...
}
If( array_key_exist(“read only”,$roles) ){
// do some stuff...
}
Is it right way to do/checking role or please give me some suggestion if there is another best way to do so.. thanks 这是做/检查角色的正确方法,还是有其他最好的方法可以给我一些建议。.谢谢
First, assuming your $_SESSION
contains the string with comma separated roles, you need to explode(',', $_SESSION['user_role'])
it to get an array of roles. 首先,假设您的
$_SESSION
包含角色以逗号分隔的字符串,则需要对其进行explode(',', $_SESSION['user_role'])
以获得角色数组。
To check if a role is contained in that array, use in_array("All", $roles)
instead of array_key_exists()
which will only search for keys, not values. 要检查该数组中是否包含角色,请使用
in_array("All", $roles)
而不是array_key_exists()
,后者仅搜索键,而不搜索值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.