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

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

متابعة

What are the major differences between sessions, cookies, session_cookie and when to use each one of them?

user-image
تم إضافة السؤال من قبل Mohammad Ateieh , Software Engineering Manager , Bayt.com
تاريخ النشر: 2013/08/26
Khadijah Shtayat
من قبل Khadijah Shtayat , Technical Lead , Opensooq

The main difference between cookies and sessions is that cookies are stored in the user's browser (clinet side), and sessions are not.
A cookie can keep information in the user's browser until deleted.
The session cookie is a server-specific cookie that cannot be passed to any machine other than the one that generated the cookie.
The session cookie allows the browser to re-identify itself to the single, unique server to which the client had previously authenticated.
When using session cookies, WebSEAL does not need to prompt the client for another login.

Zaid Rabab'a
من قبل Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.

Cookies VS sessions

Cookie stored in client side, sessions stored in server side

The session finished when you close your browser, cookie life time defined by developer

Muhammad Majid Saleem
من قبل Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

Major difference between Cookies and Session is:

- Sessions stored on server side and Cookies stored on client side.

- Sessions expire with browser and Cookies never expire with browser.

- Sessions life as long as browser stays live and Cookies life set by developer / creator.

- Sessions are browsers based and Cookies are not based on browsers.

Imran ul Haq
من قبل Imran ul Haq , Senior Backend Developer , King Abdullah City for

Session is a server side object, i.e.
it is stored on the server machine whereas Cookies are client site obect i.e.
they are stored on the clients computer Session is lost when you close the browser, whereas cookies can be programmed (persistent cookies) to keep the information on the clients computer even when the browser is closed.
To understand the difference, lets say you go to an online shopping site.
As soon as you log in, a session variable stores your information (like username, etc).
This session is maininted as long as you are on the site and shopping.
Once you checkout, the session is destroyed but the website can create a cookie to keep track of what you bought the last time.
Hence, when you visit again you can be shown suggestions depending upon your history.
session_cookie is a  cookie that is erased when the user closes his/her browser.
The session cookie is stored in temporary memory and is not retained after the browser is closed.
I hope this clears any confusion.

Nouphal Muhammed
من قبل Nouphal Muhammed , Senior Web Developer , Planet Green Solutions

Session cookie's are created when an expiration time or validity time is not specified for a cookie and they are deleted on closing the browser. They are usually used for remembering items in shopping carts  or any other similar purpose. We can set persistent cookies that will remain in the browser for a long peroid of time, for that we have to set an expiration time. 

Sessions are a way of remembering the data in between two subsequent page requests. Http is a stateless protocol. So sessions are used to provide the state information. Sessions are stored in server and simply they are a temporary storage with a id (session id) to identify each user session. The default expiration time for a session in PHP is1440 seconds.

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

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟