+ 11
Cookie vs Session
Can anybody state the difference between cookie and session in php? I am really not getting it. Thank you!
2 Respostas
+ 12
Simple.
A cookie resides on the user's computer where as a session resides on the web server.
So in other words, a session is server-side information intended to exist only throughout the visitor's interaction with the website. A cookie is placed on the users local machine with an expiry date/time which you can request when the users hits your site.
+ 4
ihateonions
Great explanation.
I would like to add:
The purpose of cookies is to store user specific data to be shared between browser tabs or windows. This is stored locally on the client machine.
The purpose of sessions, however, is to stored authentication data on the server side (typically in a database) that corresponds to a session id in the client's cookies.
So in short:
Cookies = General data/preferences
Sessions = Security/authentication