Archive for the ‘cookie’ Category
Differences between SESSION and COOKIE
Filed under: cookie, http, session, versus, web | Tags: cookie, http, session, web
Comments (3) In my previous post, I wrote about breaking the rule in using requests. How many things we are not clearly understood in web standard? This time, I try to learn another standard. What is difference between SESSION and COOKIE? I thought I knew it, but actually not. I made some Googling. And here are the results…
HTTP is stateless protocol. A stateless server is a serve that treats each request as an independent transaction that is unrelated to any previous request.
That mean, the request you make doesn’t associate in any way with the previous one. So, how about the request we want to make frequently, like user name or id? As you know, we could store our data in COOKIE. When we store data in COOKIE, the browser will send the cookie data to server for each request. We already could use SESSION for this kind of task. So, what is difference between SESSION and COOKIE?
COOKIE
A cookie is a text-only string that takes a place in the memory of user’s browser. If the lifetime of the cookie is set to be longer than the time user spends at that site, then this string is saved to file for future reference. User could be disabled the cookie in their browser setting.
SESSION
Session values are store in server side not in user’s machine. A session is available as long as the browser is opened. User couldn’t be disabled the session. We could store not only strings but also objects in session.
The Differences
We got three differences in general. The key difference would be cookies are stored in client side and sessions are stored in server side. The second difference would be cookies can only store strings. We can store our objects in sessions. Storing objects in sessions were really useful according to my experience. Another difference was that we could be save cookie for future reference, but session couldn’t. When users close their browser, they also lost the session.