Difference in session and cookie.pdf

amitgupta43438 48 views 2 slides Aug 21, 2023
Slide 1
Slide 1 of 2
Slide 1
1
Slide 2
2

About This Presentation

Both sessions and cookies are used for maintaining state and storing data on the client side in web applications, but they serve different purposes and have different characteristics. Here’s a comparison of sessions and cookies:

Cookies:

Definition: Cookies are small pieces of data stored in...


Slide Content

Differenceinsessionandcookie
Bycodexwave.g1tech.in
Aug14,2023
Bothsessionsandcookiesareusedformaintainingstateandstoringdataontheclientside
inwebapplications,buttheyservedifferentpurposesandhavedifferentcharacteristics.
Here’sacomparisonofsessionsandcookies:
Cookies:
1.Definition:Cookiesaresmallpiecesofdatastoredintheuser’sbrowser.Theyare
sentaspartofHTTPrequestsandresponsesbetweentheclientandtheserver.
2.Purpose:Cookiesareoftenusedtostoresmallamountsofdata,suchasuser
preferences,shoppingcartcontents,andauthenticationtokens.
3.SizeLimit:Cookiesarelimitedinsize(typicallyaround4KB)duetotheirsmall
storagecapacity.
4.Duration:Cookiescanhaveanexpirationdate,whichcanbesettoeitherpersist
acrossmultiplesessionsortoexpirewhenthebrowserisclosed(sessioncookie).
5.Security:CookiescanbesusceptibletosecurityvulnerabilitieslikeCross-Site
Scripting(XSS)andCross-SiteRequestForgery(CSRF)attacks.
6.Access:Cookiesareaccessibleontheclientsideandcanbemanipulatedbythe
userormaliciousscripts.
7.Storage:Cookiesarestoredaskey-valuepairsandcanbesetandretrievedusing
JavaScriptorbyHTTPheaders.
8.Scoping:Cookiescanbescopedtoaspecificdomainorpath,whichdetermines
whentheyaresenttotheserverwithHTTPrequests.
9.Usage:Cookiesarecommonlyusedformaintainingusersessions,trackinguser
behavior,andimplementingfeatureslike“RememberMe”functionality.
Sessions:
1.Definition:Sessionsareawaytomaintainuser-specificdataontheserverside.A
sessionistypicallyassociatedwithauniqueidentifierstoredinacookie.
2.Purpose:Sessionsareusedtostoremoresubstantialamountsofdataandsensitive
information,suchasuserauthenticationdetailsandtemporarydata.

3.SizeLimit:Sessionscanholdlargeramountsofdatacomparedtocookies,asthe
dataisstoredontheserverside.
4.Duration:Sessionstypicallylastaslongastheuser’svisittothewebsite.However,
sessionscanbeextended,andtheirexpirationcanbecontrolled.
5.Security:Sessionsaregenerallymoresecurethancookies,asthesessiondata
remainsontheserverandisn’tdirectlyaccessibletotheclient.
6.Access:Sessiondataisnotdirectlyaccessiblebytheclient;it’sstoredontheserver
andaccessedthroughasessionidentifier.
7.Storage:Sessiondataisstoredontheserver’smemoryoradatabase,depending
ontheserver-sidetechnologybeingused.
8.Scoping:Sessionsareusuallyscopedtoauser’sentirevisittothewebsite.
9.Usage:Sessionsareusedforuserauthentication,storingtemporarydataacross
multiplepages,andmanaginguser-specificstate.
Insummary,cookiesaremainlyusedtostoresmallamountsofdataontheclientside,while
sessionsareusedtomaintainmoreextensiveandsensitivedataontheserverside.Cookies
areaccessiblebytheclientandaresentwitheveryHTTPrequest,whilesessiondatais
storedontheserverandaccessedthroughasessionidentifier.Thechoicebetweenusing
cookiesandsessionsdependsonthespecificrequirementsoftheapplicationandthetype
ofdatabeingstored.