Register now or log in to join your professional community.
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
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.
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.