Concepts / The web

The web

HTTP cookie

Also called Set-Cookie, session cookie

A short piece of text a server gives a client, which the client sends back on every later request.

The server hands out a value, the client brings it back
The server hands out a value, the client brings it back

HTTP forgets each request once it has answered, so a server that wants to know a visitor hands out a short value with Set-Cookie. The client keeps it and sends it back with Cookie on every later request to that site, and the server looks up what it stands for. To the server, whoever holds the value is that visitor, which is why sign-in cookies travel over HTTPS only.

HTTP is stateless: nothing links one request to the next. A server sends Set-Cookie: basket=7f3a, the client stores it, and every later request to that site carries Cookie: basket=7f3a. Usually the value is only a session number, and the data stays on the server. Whoever holds the number is that visitor, so sign-in cookies are marked Secure (HTTPS only) and HttpOnly (hidden from the page's scripts).

See it on real machines

Read next

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab