+ 11

Cookie vs Session

Can anybody state the difference between cookie and session in php? I am really not getting it. Thank you!

14th Jun 2018, 9:42 AM
Jenny
Jenny - avatar
2 Answers
+ 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.
14th Jun 2018, 10:50 AM
ihateonions
+ 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
28th Jun 2018, 5:14 AM
Adam
Adam - avatar