Add a jacket to your basket, click to another page, and the jacket is still there. Come back next week and the site greets you by name. Both tricks rely on cookies: small files a website asks your browser to keep.
A cookie is a small text file sent by a web server and stored by the browser on the user's computer. It holds data about the user's visit; the browser sends it back to the site on later requests, so the site can recognise the user. A session cookie is stored in temporary memory and is deleted when the browser is closed. A persistent cookie is saved on the hard drive and remains until its expiry date or until the user deletes it.
Fig. 1: a session cookie ends with the browser session; a persistent cookie lasts until it expires
Section 01
What a cookie is.
HTTP on its own does not remember anything between one request and the next. Cookies give a website a memory. In the lab, add items to a basket, move between pages, then close and reopen the browser.
Created by the website: the web server sends the cookie with a web page.
Stored by the browser: the browser keeps it on the user's device; storing cookies is one of a browser's functions.
Sent back: each time the user requests another page from the same site, the browser sends the cookie too, so the server knows who the user is and what they did before.
Small text file: a cookie is data, not a program, so it cannot run on the computer by itself.
Section 02
Session or persistent?
The difference is how long the cookie lasts, which decides what it can be used for.
Session cookie
Persistent cookie
Stored in
Temporary memory (RAM)
The hard drive / secondary storage
Deleted
When the browser is closed
On its expiry date, or when the user deletes it
Typical use
Holding items in a shopping basket while browsing one visit
Remembering login details, preferences and personal details between visits
Examiner trap
A session cookie is not deleted when the user leaves the page or the website. It is deleted when the browser is closed.
Stage 1 · Learn
Check what the sim just showed you
Four quick checks. Each correct answer earns XP and records this skill on your profile.
Quick check+10 XP
What is a cookie?
Quick check+10 XP
In the lab, what happens to the session cookie when the browser is closed?
Quick check+10 XP
Which use needs a persistent cookie?
Quick check+10 XP
When does a persistent cookie stop being stored?
Section 03
What cookies are used for.
The syllabus names four uses. For each, be ready to say which type of cookie would be used.
Saving personal details: name, address or delivery details, so forms are filled in automatically next time (persistent).
Tracking user preferences: language, font size, dark mode, or the products a user looks at, so pages and adverts can be targeted (persistent).
Holding items in an online shopping cart: the basket is remembered as the user moves from page to page (session; some sites use persistent cookies so the basket survives until the next visit).
Storing login details: a "remember me" option keeps the user logged in, so they do not re-enter their details each visit (persistent).
Worked example Pick the type
A user logs in to a bank website. The site must log the user out as soon as they close the browser. Which type of cookie should store the login?
The login must not survive after the browser is closed.
A persistent cookie would keep the user logged in until it expired, which is a security risk on a shared computer.
A session cookie is deleted when the browser is closed.
Answer: A session cookie
Your turn
A news site shows every visitor's chosen language each time they return. Which type of cookie is used, and why?
A persistent cookie, because the preference must be kept after the browser is closed, until the user's next visit.
Stage 2 · Exam
Exam-style questions
Unlocks once the four checks above are done. Worth more XP, written to IGCSE Paper 1 standard.
Finish the four checks above to unlock the exam questions
Exam style+20 XP
Which statement about session cookies is correct?
Exam style+20 XP
Which is a use of cookies named in the syllabus?
Exam style+20 XP
Where is a persistent cookie stored?
Exam style+20 XP
A website shows adverts for trainers after a user looked at trainers last week. What made this possible?
Skill unlocked
Cookies, mastered.
This skill is now recorded on your profile. Keep the chain going.