Syllabus & Goals 3 min
Cambridge 5.1 · Cookies (session and persistent) Paper 1 · Computer Systems
By the end of this lesson you can:
- Define a cookie and describe how a website uses one.
- Compare session and persistent cookies: where stored, how long kept, what for.
- Give and explain the uses of cookies in a given scenario.
Textbook: Chapter 5, §5.1.6 (pp. 184–186)
Recap / Warm-Up 5 min
Last lesson: the browser finds a page through the DNS, then fetches it from the web server. One browser function we skipped was storing cookies.
Quick starter
You visit a shopping site, choose "English" and "$", then close the browser. Next week the site opens in English with prices in dollars. How could it remember you?
Reveal the answer
The site stored a small file — a cookie — on your computer. On your next visit the browser sent it back, and the site read your saved preferences from it.
Key Concept 14 min
1 · What is a cookie?
A cookie is a small file (or piece of code) that a web server sends to a browser. The browser stores it on the user's computer. Each cookie works like a tiny look-up table of (key, data) pairs, such as (language, English).
On each visit, the website checks whether it has set cookies in this browser before. If so, the browser sends them back. The site reads them to recognise the user, restore preferences, and customise the page — for example, "Customers who bought this also bought…".
2 · Two types: session and persistent
A cookie with no expiry date is always a session cookie. A cookie that has one is a persistent (or permanent) cookie.
| Session cookie | Persistent cookie | |
|---|---|---|
| Stored in | Temporary memory (RAM) on the computer | The hard drive (secondary storage) |
| Lasts until | The browser is closed or the website session ends | Its expiry date is reached, or the user deletes it |
| Expiry date? | No | Yes |
| Typical use | Keeps items in a virtual shopping basket while you shop | Remembers log-in details and preferences between visits |
| Identifies the user? | No — collects no personal information | Can do — may hold personal data (legitimate sites encrypt it) |
3 · What cookies are used for
Uses of (mostly persistent) cookies that Cambridge credits:
Convenience for the user
- Remember log-in details, email and delivery details, so they are not retyped
- Recognise the user on every visit
- Save items in a virtual shopping basket
- Store preferences, such as a customised page layout
- Show the page in the user's language automatically
- Save progress in online games and quizzes
Benefit to the website
- Track browsing habits, history and favourites
- Target adverts that match past buying or browsing
- Support online financial transactions
- Let social networks recognise preferences
- Avoid storing huge amounts of user data on the server itself
What a cookie banner typically looks like (mock-up)
We use cookies
Essential cookies keep your basket and log-in working. Preference cookies remember your language. Advertising cookies track visits to show relevant adverts.
[ Accept all ] [ Essential only ] [ Choose settings ]
Worked Example 12 min
(a) Track the cookies through a shopping trip
Scenario: Sam visits an online bookshop for the first time. Work out which cookies exist after each event.
| Event | Session cookie | Persistent cookie | Why |
|---|---|---|---|
| 1. Sam chooses English and $ | — | language=English; currency=$ | Preferences must survive future visits, so an expiry date is set. |
| 2. Sam adds two books to the basket | basket=2 items | unchanged | The basket is only needed while shopping. |
| 3. Sam logs in and ticks "Remember me" | basket=2 items | + login=sam (encrypted) | Saves retyping the password next time. |
| 4. Sam closes the browser | deleted | still on the hard drive | Session cookies are held in temporary memory only. |
| 5. Sam returns next week | new, empty | sent to the site | The site recognises Sam, logs in automatically and shows English and $. |
Check your reasoning: at event 5 the basket is empty. If the shop wanted to keep the basket, it would need a persistent cookie (or to store the basket on its server against Sam's account).
(b) Build a 4-mark comparison answer
Question: compare session cookies and persistent cookies. [4]
- Point 1 — storage: session cookies are stored in temporary memory; persistent cookies on the hard drive."compare" needs both sides in one sentence to earn the mark safely.
- Point 2 — lifetime: a session cookie is deleted when the browser closes; a persistent cookie stays until its expiry date or until the user deletes it.this is the difference examiners expect first.
- Point 3 — expiry date: session cookies have none; persistent cookies do.a separate, creditable fact.
- Point 4 — purpose: session cookies hold a virtual shopping basket; persistent cookies remember log-in details and preferences between visits.linking type to a use shows understanding.
(c) Session or persistent?
| Situation | Type | Deciding clue |
|---|---|---|
| A quiz site remembers you reached level 12 last month | Persistent | Data survived across visits. |
| A cinema site holds your seat choice while you pay | Session | Needed only during this session. |
| A news site shows adverts for trainers you viewed elsewhere | Persistent (tracking) | Browsing history kept over time. |
| A cookie with no expiry date | Session | No expiry date means session, by definition. |
Try It Yourself 12 min
Goal: give two differences between a session cookie and a persistent cookie.
Goal: a music-streaming website uses cookies. Describe three ways the cookies improve the experience for a returning listener.
Goal: explain why persistent cookies are sometimes called "tracking cookies". Give at least two pieces of evidence, then suggest one thing a user can do about it.
Hint
Think about what they record (history, preferences), how long they last, and who else the data is shared with. Browser privacy settings will come up again in Lesson 10.
📝 Exam Practice 10 min
State what is meant by a cookie.
Mark scheme
- A small (text) file sent by a web server and stored by the browser on the user's computer, holding data such as preferences (1).
Compare session cookies and persistent cookies.
Mark scheme
Any four from:
- Session cookies are stored in temporary memory / RAM; persistent cookies on the hard drive (1).
- Session cookies are deleted when the browser is closed / session ends (1).
- Persistent cookies remain until the expiry date / until deleted by the user (1).
- Session cookies have no expiry date; persistent cookies do (1).
- Session cookies do not identify the user / collect personal data; persistent cookies can (1).
- Session: e.g. virtual shopping basket; persistent: e.g. remembering log-in details (1).
An online clothes shop uses persistent cookies. Give three uses the shop could make of them.
Mark scheme
Any three from:
- Remember log-in details / passwords / delivery details (1).
- Recognise the user on each visit (1).
- Store user preferences, e.g. language, currency, size (1).
- Track browsing / buying history (1).
- Target adverts / recommendations to the user (1).
- Keep items in the shopping basket between visits (1).
Explain why some users are concerned about persistent cookies.
Mark scheme
- They track the user's browsing activity / history over time (1)…
- …and this data may be shared with third parties / advertisers without the user fully realising, which is a privacy concern (1).
Recap & Key Terms 3 min
A cookie is a small file of key–data pairs that a web server asks the browser to store. Session cookies live in temporary memory and vanish when the browser closes. Persistent cookies sit on the hard drive until they expire, so sites can recognise users, keep preferences and track habits.
- Cookie
- A text file sent from a website to a user's browser, used to remember user preferences each time they visit.
- Session cookie
- A cookie stored temporarily; deleted when the browser is closed or the website session ends.
- Persistent cookie
- A cookie stored on the hard drive; only deleted when its expiry date is reached or the user deletes it.
- User preferences
- Settings stored in cookies that remember customised pages or browsing history to target adverts.
- Virtual shopping basket
- An area of memory where items a user wants to buy are held until payment is made or the session ends.
Homework 1 min
Task (≤ 15 min): an online game website lets players log in, choose a language and buy items from an in-game shop. Describe how the website could use both a session cookie and a persistent cookie. [4]
Model answer
- A session cookie could hold the items in the player's shop basket during this visit (1)…
- …and it is deleted when the browser closes / the session ends (1).
- A persistent cookie could store the player's log-in details / language / game progress (1)…
- …on the hard drive until it expires, so the player is recognised and the settings reload next time (1).