Shelby Week 4 HW

The Differences Between Cookies and Sessions PHP

Article link:

Tutorialspoint

Cookies and sessions within PHP are similar in the way that they both collect data from a user using a website or application and that data can be used to continue a user's browsing history. The similarity stops there though as cookies and sessions are stored differently, expire under different circumstances, have completely seperate safety precautions, and data memory capacities. Cookies can be described as text file information saved and accessed only on the user's computer/device that tracks the activity of the user on a website or application. Sessions are temporarily collected user data stored within a server that tracks a user's time spent within the website/application.

Cookies are different from sessions as they are created with HTTP headers, kept on the user's computer/device, track all activites of the user while browsing a website, and expire after a specified amount of time. Cookies can only accessed by that specific user's browser. Cookies are kept as text that can be obtained from the HTTP header and manipulated. Cookies save the information of the user so that any time they access that website or application anything saved for the user's preference or from user action stays relevant from their browser. Other differences cookies have from sessions is that cookies are stored with up to 4 KB of data but require no beginning function to start.

Sessions are different from cookies as they store the user's data within the server, does not track the user's activities, and exits the session when the user leaves the website/application or shuts off their computer. The user data saved from a session stays within the database so a user can be recognized when logging in. This session is kept as a unique number in the form of a cookie, form field, or URL. Other differences sessions have from cookies is an unlimited amount of data kept in storage, memory capacity at 128 megabytes unless during a session, and a start() method required before a user starts a session.