如何在php中检查用户角色的db调用?

问题描述:

I know the standard way to check user roles mostly like if(isUserAuthorizedForTheOperation(userId)) in PHP which is create a db and for every user check the db and find out.Now this adds to immense performace issues.For every hit in my .php file,I find it extremly costly to query the database.What is the alternative?

我知道检查用户角色的标准方法,主要是像 if(isUserAuthorizedForTheOperation(userId)) code >在PHP中创建一个数据库,并为每个用户检查数据库并查找。现在这增加了巨大的性能问题。对于我的.php文件中的每一个命中,我发现查询数据库的成本极高。什么是替代方案 ? p> div>

Do you perform one query per hit/session or multiple? Make sure you only load in the roles once, store it in a (session) variable, and then keep checking that variable - instead of performing a query for every time you want to check.

(Taken from the comments as OP said it answered his question.)