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?
Sessions are stored on the server, which means clients do not have access to the information you store about them. Session data, being stored on your server, does not need to be transmitted in full with each page; clients just need to send an ID and the data is loaded from the server.
On the other hand, cookies are stored on the client. They can be made durable for a long time and would allow you to work more smoothly when you have a cluster of web servers. However, unlike sessions, data stored in cookies is transmitted in full with each page request.
Avoid storing data in cookies
What you can store in session data depends on the amount of data and number of users you have. no_of_users * size_of_session_data must be less than the free memory available on your server.
no_of_users
size_of_session_data
1.4m articles
1.4m replys
5 comments
57.0k users