Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

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

user-image
Question added by Mohammad Ateieh , Software Engineering Manager , Bayt.com
Date Posted: 2013/08/26
Khadijah Shtayat
by 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
by 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
by 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
by 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
by 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.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.