Sessions
Session starts when you request the server for the first time and it remains till you close that site. The amount of time you have spent on the site is called a session. As sessions get deleted when the connection to the client and server gets closed, so we have to store the session data somewhere to reuse them again in future.
Cookies
Cookies are the information stored on the client’s browser by the server. It helps in tracking the user and for various personalized recommendations.
Difference between Sessions and Cookies
Sessions
- Sessions are the data stored on the server side.
- The amount of data we can store on server is very large.
- Sessions are a secure way to store the data as it can’t be read by anyone.
- Sessions can be deleted whenever required.
- Sessions are used to store confidential informations.
Cookies
- Cookies are the data stored on the client’s browser.
- Maximum size of cookies can be 4 KB.
- Cookies are not secured, as they can be read by anyone.
- Cookies can be deleted whenever required. We can also set expiration period of cookies, after that period the cookies will get deleted.
- Cookies must not be used for storing confidential informations as it can be read by anyone.