When should I use session variables instead of cookies?

前端 未结 12 764
囚心锁ツ
囚心锁ツ 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条回答
  •  猫巷女王i
    2020-12-07 11:54

    Sessions are stored on the server side. If a visitor stores something in a cookie, the browser will send the user information for every request made.

    This tends to consume a lot of servers computer time and slowing the user's experience. Some browsers also do not support cookies giving more advantage to sessions over cookies... I strongly recommend sessions.

    This might help: Cookies (php.net)

提交回复
热议问题