dongqi4085 2013-03-12 11:46 采纳率: 0%
浏览 46

如何在$ _SESSION上决定何时使用数据库

I have had a quick search, and it seems all the related questions don't quite get to my point, or are too specific to help me out.

My first consideration is performance. My understanding is that by default storing information within $_SESSION means the server writes a file to disk. For a small LAMP server or a basic, small hosted website, how big would your $_SESSION variable need to get before a database becomes a more efficient option. Would 10, 100, 1000, 10000 array members in $_SESSION be where you begin to consider using a database instead? Or is traffic more of a consideration?

The second consideration is security. In some other answers I have seen statements like "never ever store xxx in the $_SESSION variable". Does storing information in a database actually make it more secure than $_SESSION, or can be $_SESSION be made as secure as the database given the server is set up correctly?

My feeling is that many sites developed out in the wild would start off using $_SESSION to begin with, and not necessarily get refactored to use the database. If you can redirect the $_SESSION variable from a file to the database anyway, it is always better to use $_SESSION and later point that at a database if performance is an issue?

Are there any other considerations to make for this design choice?

  • 写回答

3条回答 默认 最新

  • dssjxvbv918586 2013-03-12 11:53
    关注

    I don't think I would worry to much about the size of your session file, granted it is more scalable to use a database, I doubt you will notice a vast performance difference for a small to medium site.

    As for the security aspect, It would not be recommended to store user data in a session (username, hash, email). If you wanted to use purely sessions you could look into encrypting your session which many frameworks like CodeIgniter offer.

    So to conclude, In my opinion you should always be using the database for user information (including IP address) and sessions for general data (search terms, analytics etc...)

    Hope this helps you with your decision.

    Regards, James

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧