Description: this article is talking about some difference between cookies and session
Session and Cookies
The session and cookies are used by different websites for storing user’s data across different pages of the site. Both session and cookies are important as they keep track of the information provided by a visitor for different purpose. The main different between both of them is that session are saved on theserver-side, whereas cookies are saved on the user’s browser or client-side.
Session
A seesion is used to temporarily store the information on the server to be used across multiple pages of the website. It is the total time used for an activity. The user session starts when he logs-in to a particular network application and ends when the user logs out from the application or shutdowns the system.
When we work on application over the internet, the webserver doesn’t know the user because the HTTP protocol doesn’t maintain the state. The user information provided by the user on one page of the application will not transferred to another page. To remove this limitation, sessions are used. Session gets started whenever a vistor first enters a website.
The user formation is stored in session variables, and these variables can store any type of value or data type of an Object.
Session values are much secured as these are stored in binary form or encrypted form and can only be decrypted at the server. The session values are automatically remove when the user shutdowns the system or louout from the application. To store the values permanently, we need to store them in the database.
Each session is unique for each user, and any number of sessions can be used in an application; there is not limitation to it.
The user is identified with the help of sessionID, which is a unique number saved inside the server. It is saved as a cookie, form field, or URL.
Cookie
A cookie is a small text file that is stored on the user’s computer. The maximum file size of a cookie is 4KB. It is also known as an HTTP cookie, web cookie, or internet Cookie. Whenever a user visits a website for the first time, the site sends packets of data in the form of a cookie to the user’s computer.
The cookies help the website to keep track of the user’s browsing history or cart information when they visit theor sites.
It stores only the “String” data types.
The information stored within cookies is not secure because this infomation is stored in text-format on the client-side, which can be read by anyone.
We can enable or diable the cookied as per the requirement.
The cookies generated by a user are only shown to them, and not other user can see those cookies.
Cookies are created and shared between the server and browser with the help of an HTTP header.
The path where the cookies are saved is decided by the browser, as Internet exploer usually stored them in Temporal Internet File Folder.