← IGCSE Computer Science Paper 1

Cookie use: saving personal details

A cookie can save personal details like your name or address, so forms are autofilled and you are greeted by name on later visits. A persistent cookie suits this.

Understanding Cookie use: saving personal details in IGCSE Computer Science Paper 1

What it does: The name was stored in the cookie on an earlier visit, so the site can read it and greet the visitor on the next visit. The Expires date makes it a persistent cookie, so the saved address is still there on later visits and can fill in forms. Cookies are small text files stored on the user's device by the web browser, and sent back to the site on later visits.

Common mistakes: A persistent cookie must keep the saved name after the browser closes, so it needs a future expiry such as 365 DAYS. Ending at the end of the session would make it a session cookie. Joining the greeting text to the saved name needs the + (concatenation) operator, not -. It should be OUTPUT "Welcome back " + n.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 490–499) and word search (Modules 490–509).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A website remembers your name and greets you with 'Welcome back, Sam!' on your next visit. What has it used?
A cookie that saved your personal detailsA DNS server that saved your name
Matches
Set-Cookie: name=Aisha (session cookie, deleted when the browser closes)
↓
A session cookie is wrong for saving personal details, because it is deleted when the browser closes and the name is lost before the next visit. A persistent cookie is needed.
Applying
Meanings
Term
cookie personal details
Meaning
A cookie can save personal details like your name or address, so forms are autofilled and you are greeted by name on later visits. A persistent cookie suits this.
Practice
IF cookie "name" EXISTS THEN
Testing
Gaps
: name=Sam; Max-Age=2592000
Check Answer
Spots
3SET COOKIE TYPE persistent
4SET EXPIRY END OF SESSION

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Hyena' badge — Savannah Debugger, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A website remembers your name and greets you with 'Welcome back, Sam!' on your next visit. What has it used?
A. A cookie that saved your personal details ✓
B. A DNS server that saved your name
A cookie stored on your device holds your details, so the site can greet you by name when you return.
2. Which is an example of a cookie saving personal details?
A. The page loads faster because the server has more RAM
B. Your address is filled in automatically on a checkout form ✓
Autofilling forms is a use of cookies. The cookie stores details such as your name or address from an earlier visit.
3. Which type of cookie suits saving your name and address for next time?
A. Persistent cookie ✓
B. Session cookie
The details must still be there on a later visit, so the cookie must last after the browser closes. That is a persistent cookie.
4. Why is a session cookie a poor choice for remembering your name for next week?
A. It can only store numbers, not text
B. It is deleted when the browser is closed ✓
A session cookie only lasts while the browser is open. It is gone by the next visit, so it cannot greet you by name.
5. What is the benefit of a cookie that saves your personal details in a sign-up form?
A. You do not need to type the same details again ✓
B. The website is changed from HTTP to HTTPS
Autofilled forms save the user time because the cookie supplies details such as name or address.

Match the Pairs

Set-Cookie: name=Aisha; Max-Age=2592000 → Saves the user's name in a persistent cookie for 30 days so the site can greet her on later visits
<input type="text" name="address" autocomplete="street-address"> → A form box the browser can autofill with a saved address from an earlier visit
A site greets a returning visitor by name using personal details saved in a cookie → print("Welcome back, " + cookie_name)
A persistent cookie suits saving personal details because it lasts after the browser is closed → Set-Cookie: address=12 Oak Road; Expires=Fri, 01 Jan 2027 00:00:00 GMT
Set-Cookie: name=Aisha (session cookie, deleted when the browser closes) → A session cookie is wrong for saving personal details, because it is deleted when the browser closes and the name is lost before the next visit. A persistent cookie is needed.
The cookie stores the user's name, so the web server does not need to see it again → The browser sends the cookie back to the web server, which reads the saved details to fill in forms or greet the user. The cookie does not replace the server.

Key Term

cookie personal details
A cookie can save personal details like your name or address, so forms are autofilled and you are greeted by name on later visits. A persistent cookie suits this.

Fill in the Blanks

1. Set-Cookie: name=Sam; Max-Age=2592000
Hint: Type the name of the HTTP response header a server uses to send a saved name to the browser.
2. Set-Cookie: name=Sam; Max-Age=2592000
Hint: Type the attribute that sets how many seconds the data lasts, making it persistent.
3. IF savedName <> "" THEN OUTPUT "Welcome back, " + savedName ENDIF
Hint: Type the pseudocode operator meaning 'not equal to', to check that a name was saved.
4. document.cookie = "name=Sam; max-age=86400";
Hint: Type the property of document that lets JavaScript save small pieces of user data in the browser.
5. IF savedAddress <> "" THEN addressBox ← savedAddress ENDIF
Hint: Type the variable holding the address read from the saved data, so the form field is autofilled.

Spot the Error

Question 1
A name ← INPUT("Your name")
B SAVE name IN COOKIE "user"
C SET COOKIE TYPE persistent
D SET EXPIRY END OF SESSION
Line D — A persistent cookie must keep the saved name after the browser closes, so it needs a future expiry such as 365 DAYS. Ending at the end of the session would make it a session cookie.
Question 2
A n ← READ COOKIE "name"
B IF n <> "" THEN
C OUTPUT "Welcome back " - n
D ENDIF
Line C — Joining the greeting text to the saved name needs the + (concatenation) operator, not -. It should be OUTPUT "Welcome back " + n.
Question 3
A addr ← READ COOKIE "name"
B SET addressBox TO addr
C SHOW form
Line A — The address must be read from the cookie that stores the address. Reading the "name" cookie would autofill the wrong detail. It should be READ COOKIE "addr".
Question 4
A name ← INPUT("Your name")
B DELETE COOKIE "user"
C OUTPUT "Saved!"
Line B — The program should save the user's name in a cookie so it can be used on later visits. DELETE would remove the cookie. It should be SAVE name IN COOKIE "user".
Question 5
A IF COOKIE "name" IS EMPTY THEN
B FILL nameBox WITH cookie
C ELSE
D SHOW empty form
E ENDIF
Line A — The form should only be autofilled when the cookie exists. Testing for an empty cookie reverses the logic. It should be IF COOKIE "name" EXISTS THEN.

Student with a class code? Join your class →