Guided Notes
Cookies, Sessions & Error Handling
Remembering users with cookies and sessions, login flows, exceptions with try/catch/finally, custom exceptions, and error reporting.
Cookies
Slide 1 / 5A cookie is a small value stored in the browser and sent back with every request: setcookie('theme', 'dark', [ 'expires' => time() + 86400 * 30, 'path' => '/', 'secure' => true, 'httponly' => true, 'samesite' => 'Lax', ]);
Read it later with $_COOKIE['theme'] ?? 'light'. Call setcookie before any output. Users can see and change cookies — never store secrets or trust their values without validation.
