Skip to content
Back to Path
Module 13 of 18

Cookies & State

By itself, HTTP has no memory. Cookies are small pieces of data that the server asks the browser to "hold onto" so it can recognize the user later.

Interactive Protocol Simulation
Step 1 / 4

Step 1 of 4

User-Agent:Browser Info
Mozilla/5.0...
Accept:Preference
text/html
Host:Destination
example.com
Cookie:Identity
session_id=123

Worked example

Request

GET /profile HTTP/1.1
Cookie: user_id=123; theme=dark

Response

HTTP/1.1 200 OK
Set-Cookie: last_visit=2025-12-20

The browser "remembers" the user_id from a previous visit and sends it back automatically. The server then updates the last_visit time.

The "Stateless" Problem

Stateless means the server treats every request as if it’s from a total stranger. To fix this, we use the "Set-Cookie" header.

Cookie Workflow

  • Step 1 — User logs in.
  • Step 2 — Server sends a response with "Set-Cookie: session_id=abc".
  • Step 3 — Browser saves that cookie.
  • Step 4 — On the next visit, the browser automatically sends "Cookie: session_id=abc".

Study kit

Module 13 of 18

Intermediate · 3 min · 0 of 18 complete

Module status

Not completed yet

Notessaved locally+

Notes stay in this browser. They are not uploaded.

Suggest an edit

Discussion

0 comments

Loading discussion…

Sign in to ask a question.