duandanxiu6965 2012-10-05 22:34
浏览 69
已采纳

PHP:保存用户登录后选择的角色的最佳做法

I am using Symfony2 but this question is pretty general.

I want to login a user and right after the login, let him choose from a certain amount of "roles". These roles are objects in the database carrying a lot of configuration with them.

Question: What is the best practice of storing what role the User chose?

Session? But it's bad practice to store objects in sessions, isn't it? Id of the role in the Session? Id (or a hash of it) of the role in a cookie?

Thanks for your thoughts.

  • 写回答

3条回答 默认 最新

  • dongyang2229 2012-10-05 22:45
    关注

    Definitely store the session ID instead of the whole object. Specially if the object's data won't change from user to user. In fact, if the object's data won't change over time, you could potentially use one of several techniques to cache it.

    Whether you use cookies or sessions to store the information depends on your requirements. If you need to store additional data (other than the ID of the role), and require such data to be safe from being edited, then you should consider using sessions, since they prevent the user from editing the stored data manually. Otherwise, using cookies is more efficient, since the server doesn't have to deal with all the hassle of session storing and retrieving.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题