ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Sessions vs. Cookies - What is the difference?

user-image
تم إضافة السؤال من قبل Zaid Rabab'a , Technical Team Lead , ESKADENIA Software
تاريخ النشر: 2013/01/16
THIKRALLAH SHREAH
من قبل THIKRALLAH SHREAH , Technical Team Leader , bayt.com

cookies and sessions are completely different things, they are like "oranges" and "apples", i.e different categories.
Cookie, is part of the HTTP protocol, which allows server & possibly the client side to save and retrieve data while the user is browsing a site, cookie is a small storage on the client (usually browser) side.
HTTP protocol is stateless, so to keep the user with a state, Web "session" has been defined.
The web session is a context and it get saved somewhere.
The context saves the user state, and any other info related to the user browsing.
Now, cookies are used to save parts of the session context in most websites.
most of Session context information saved by the server side in a a Cache or DB.
Cookies are dataStore, Sessions is a Web concept to overcome the stateless HTTP (apples and oranges).
Yet Sessions state utilize cookies in most web-sites, but that doesn't mean cookies are the only option, but cookies are the most convenient way.

marwa khalaf
من قبل marwa khalaf , .Net Developer , Sands National Academy

A cookie can keep information in the user's browser until deleted.
If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit.
You can store almost anything in a browser cookie.
The trouble is that a user can block cookies or delete them at any time.
If, for example, your website's shopping cart utilized cookies, and a person had their browser set to block them, then they could not shop at your website.

yazan Ahmad
من قبل yazan Ahmad

Sessions are not reliant on the user allowing a cookie.
They work instead like a token allowing access and passing information while the user has their browser open.
The problem with sessions is that when you close your browser you also lose the session.
So, if you had a site requiring a login, this couldn't be saved as a session like it could as a cookie, and the user would be forced to re-login every time they visit

Omar Alsoudani
من قبل Omar Alsoudani , Software Engineer , Codeobia , Amman

The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not.
This difference determines what each is best used for.

Mostafa Shamout
من قبل Mostafa Shamout , Web Designer , Freelance

You can of course get the best of both worlds! Once you know what each does, you can use a combination of cookies and sessions to make your site work exactly the way you want it to.

Farhan Noor
من قبل Farhan Noor , Senior WordPress Developer , Spider Teams LLC

Cookies and sessions, both are used to save small information to perform different functions, mostly identification information.

Cookies are smal files to save data on client side.

Session is a variable used to save small data on server side.

المزيد من الأسئلة المماثلة