Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Difference between Session and Cookies

  • Difficulty Level : Basic
  • Last Updated : 25 Oct, 2021

1. Session :
A session is used to save information on the server momentarily so that it may be utilized across various pages of the website. It is the overall amount of time spent on an activity. The user session begins when the user logs in to a specific network application and ends when the user logs out of the program or shuts down the machine.

Session values are far more secure since they are saved in binary or encrypted form and can only be decoded at the server. When the user shuts down the machine or logs out of the program, the session values are automatically deleted. We must save the values in the database to keep them forever.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

 

2. Cookie :
A cookie is a small text file that is saved on the user’s computer. The maximum file size for a cookie is 4KB. It is also known as an HTTP cookie, a web cookie, or an internet cookie. When a user first visits a website, the site sends data packets to the user’s computer in the form of a cookie.



The information stored in cookies is not safe since it is kept on the client-side in a text format that anybody can see. We can activate or disable cookies based on our needs.

Difference Between Session and Cookies :

Cookie

Session

Cookies are client-side files on a local computer that hold user information.Sessions are server-side files that contain user data.
Cookies end on the lifetime set by the user.When the user quits the browser or logs out of the programmed, the session is over.
It can only store a certain amount of info.It can hold an indefinite quantity of data.
The browser’s cookies have a maximum capacity of 4 KB.We can keep as much data as we like within a session, however there is a maximum memory restriction of 128 MB that a script may consume at one time.
Because cookies are kept on the local computer, we don’t need to run a function to start them.To begin the session, we must use the session start() method.
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!