CST463 · S7 CSE

Cookie management lifecycle

How a cookie is created, read, updated and deleted between the browser and the PHP server.

Module 4 Back to CST463 hub

Source: php_cookie_management.pdf — course material by Kiran V.K., published here so it is readable without a Google account.

The cookie lifecycle as covered in class — how a cookie is created, read, updated and deleted across the request/response cycle between the browser and the PHP server.

Sequence diagram: cookie management lifecycle between browser and PHP server
Cookie Management Lifecycle — browser and PHP server.

The sequence, in words

  1. Creation — the PHP server receives a request to create a cookie and replies with an HTTP response carrying a Set-Cookie header; the browser stores it.
  2. Reading — every subsequent request from the browser carries the cookie, and the server reads it through $_COOKIE.
  3. Modification — the server sends a new Set-Cookie header and the browser updates its stored value.
  4. Deletion — the server sends a Set-Cookie header with an expiry in the past, and the browser deletes the cookie.