- Cookies store data in the browser to maintain state between requests, while sessions store data on the server. Sessions associate a cookie containing a unique ID with data stored server-side.
- PHP provides the $_SESSION superglobal array to access session data. session_start() must be called before accessing $_SESSION. Data can be stored and retrieved across requests.
- Websites use login/logout to control access by storing user data in the session on login and destroying the session on logout. The POST/redirect pattern avoids duplicate form submissions on refresh by redirecting after form submission.