The basic task of both cookies and sessions is to store visitor data so that it can be accessed by every page on a website.
Cookies are small text files that are stored in the visitor’s browser for a specific time or for a long -lifespan. Cookies can be edited by the visitor. in short Cookies are client-side files that contain user information.
Sessions are small files that are stored on the website’s server. Sessions have a limited lifespan, they expire when the browser is closed or logged out from the session. Sessions cannot be edited by the visitor or user. Session Max life time is 1440 Seconds(24 Minutes) as defined in php.ini file however you may change it accordingly
In short, cookies serve on the visitor’s computer and sessions serve on server.
By giving each visitor a cookie with a unique ID, I can use that cookie to recognize each visitor when they return. I can then use sessions to handle the page-to-page data exchange that actually provides each visitor with their customized settings and information, which are provided by each visitor and stored in a database until they are reference by the unique ID stored in the cookie.