Sessions and Cookies

It will carry discussion on general topics. It may vary from ece, cse, coding and anything which helps in both growth and development
Post Reply
learner
Posts: 7
Joined: 28 Mar 2019

Sessions and Cookies

Post by learner » 29 Mar 2019

Can anyone explain what is the difference between cookies and sessions. I also want to know where cookies are used. This topic is really complex for me.

User avatar
Aisangam
Site Admin
Posts: 22
Joined: 24 Mar 2019
Location: Delhi, India
Contact:

Re: Sessions and Cookies

Post by Aisangam » 29 Mar 2019

Thanks for the Questions. This is not as difficult as you think. Please see the below solution

To understand the difference between session and cookies, please understand the concept of http. What is http is an important question which should come to us if you are sending request or receive response from the server. HTTP is stateless. It takes your request or take response from the server. Problem with it is whenever new action is performed it generates new request. Look at facebook, if it uses only http then for every new action such as updating the comment, uploading the photo or going on your timeline a new request will be generated. Millions of users are using facebook. Using only http facebook cannot know who is the user who is doing which action.
To Resolve the above problem, it is important to make the http protocol as stateful. Sessions and cookies are used to make it stateful so that previous action can be remembered and how has performed it. But there is difference between session and cookies. Let us see these as below

Session
1.) Data is stored on the server
2.) Session data never travel with the http request and hence is more secure.
3.) Since sessions are created on the server side, hence large amount of data can be stored on these.
4.) They exist for only some time about 24 minutes
Cookies
1.) Data is stored on client side or the browser.
2.) Since cookies travel with each http request and hence are considered as less secure.
3.) As we know cookies are on client side or on the client browser, they store data in kb (about 4 kB) and only in string form.
4.) Cookies are created permanently until client/user delete it from browser

Where cookies are used
Since we have gone through the basics of cookies, you must know the importance of cookies. We have seen you tube recommends the songs of your choice or e-commerce sites recommend you product based on your choice. Have you ever thought how it happens. All this happens as these sites your cookies and based on your choice recommends you.

Post Reply