/    Sign up×
Community /Pin to ProfileBookmark

Sessions vs. Cookies

What exactly is the difference between sessions and setting cookies?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@FrostBiteFeb 21.2008 — There's not much of a difference at all. Sessions hold data for the life of the web browser. As soon as you close the browser the sessions expire. Cookies can be set to hold data for a determined period of time. In essence, they're the same ? www.Tizag.com has some great tutorials on sessions and cookies.

Hope this helps

-Frosty
Copy linkTweet thisAlerts:
@NogDogFeb 21.2008 — There's not much of a difference at all. Sessions hold data for the life of the web browser. As soon as you close the browser the sessions expire. Cookies can be set to hold data for a determined period of time. In essence, they're the same ? www.Tizag.com has some great tutorials on sessions and cookies.

Hope this helps

-Frosty[/QUOTE]

No, sessions can be configured to last any amount of time. It's just that the [i]default[/i] PHP settings have the session.cookie_lifetime set to zero, which means until the browser is closed.

The main difference between sessions and cookies is that sessions only need to save one cookie value on the client (browser), which is the session ID. All other data associated with a session are saved on the server, either in a file if you use the normal session functions and configuration or in a database if you choose to implement your own session handler functions.
Copy linkTweet thisAlerts:
@FrostBiteFeb 21.2008 — Thanks for the correction ? forgot to mention that sessions were server-side.
×

Success!

Help @Joseph_Witchard spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.9,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...