When should I use session variables instead of cookies?

前端 未结 12 761
囚心锁ツ
囚心锁ツ 2020-12-07 11:12

Session variables and cookies seem very similar to me. I understand the technical differences, but how do you decide when to use one vs. the other?

12条回答
  •  悲哀的现实
    2020-12-07 11:50

    Cookies are sent to the server on every request, so if you plan to store a fair amount of data, store it in a session.

    Otherwise, if you are storing small amounts of data, a cookie will be fine.

    Any sensitive data should be stored in a session, as cookies are not 100% secure. An advantage of cookies is that you can save memory on your server that would normally be storing session data.

提交回复
热议问题