开发者

Check user Group Level via session or database?

When the Customer or Admin have logged in, their memb开发者_如何学Cer_id will be stored in the session ($_SESSION['member_id'])

There are number of group levels, is it better to store in the session like this:

$_SESSION['group_id'] = 2;

or check the group level from the database?

SELECT group_id FROM users where member_id = .  $_SESSION['member_id'];

I have written Users Login class for the frontend, there is nothing wrong using same class for the backend?


If you have the member_id stored in a session variable, why not have group_id ? session variables allow persistance in your data between requests and that seems to be what you need.

Although some do recommend to keep session data at a minimin, ie:

 $_SESSION['uid'] = 5;
 $_SESSION['logged_on'] = true;

I would not consider having group_id as bad usage of session vars since in your case member_id depends on group_id to do anything.


The main difference between the two is that, in the first case changes to the user's group might only be visible in the next session (e.g. user is logged in, and an admin changes the group) whereas in the other they'll take immediate effect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜