← IGCSE Computer Science Paper 1

Cookie use: holding items in an online shopping cart

A cookie that remembers which items a user has added to an online shopping cart, so the cart is not emptied as they move between pages. It can last one visit or be kept for later.

Understanding Cookie use: holding items in an online shopping cart in IGCSE Computer Science Paper 1

What it does: With no expiry time set, this is a session cookie. It holds the cart during one visit and is deleted when the browser closes. The whole point of a shopping cart cookie is that the cart survives moving from page to page. The cookie name and value hold the cart items, so the cart can be remembered as the user moves between pages.

Common mistakes: The cart must be stored in the cookie so it survives the move to the next page. Deleting it would empty the cart. It should be STORE cart IN cookie. Writing "empty" overwrites the cookie and loses the items. The updated cart, including the shoes, should be written back: WRITE cart TO cookie.

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 student adds a pair of trainers to an online shopping cart, then clicks to another page of the shop. What lets the website remember the trainers are still in the cart?
The web page is automatically saved on the DNS serverA cookie stored by the browser remembers the cart items
Matches
Page 1: cart=hat. Page 2: no cookie sent, cart is empty
↓
The browser did not send the cart cookie back to the server on page 2, so the server forgot the item. The cookie must be sent with each request so the cart survives moving between pages.
Applying
Meanings
Term
shopping cart cookie
Meaning
A cookie that remembers which items a user has added to an online shopping cart, so the cart is not emptied as they move between pages. It can last one visit or be kept for later.
Practice
IF cookie "cart" EXISTS THEN
Testing
Gaps
: cart=item42
Check Answer
Spots
2cart ← cart + item
3DELETE cart FROM cookie

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

The 'Dumbo Octopus' badge — Module Maker, 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 student adds a pair of trainers to an online shopping cart, then clicks to another page of the shop. What lets the website remember the trainers are still in the cart?
A. The web page is automatically saved on the DNS server
B. A cookie stored by the browser remembers the cart items ✓
A cookie stores data about the cart in the browser, so the cart is not emptied when the user moves between pages. DNS only turns domain names into IP addresses.
2. Which statement about a shopping cart cookie is correct?
A. It keeps the cart contents as the user moves between pages ✓
B. It empties the cart every time a new page loads
The whole point of a shopping cart cookie is that the cart survives moving from page to page.
3. A shop only needs the cart to last for one shopping visit. Which type of cookie suits this best?
A. Session cookie ✓
B. Persistent cookie
A session cookie is deleted when the browser is closed, which suits a cart used during a single visit.
4. A shop wants a customer's cart to still be there when they come back tomorrow. Which type of cookie is needed?
A. Persistent cookie ✓
B. Session cookie
A persistent cookie is stored on the device until its expiry date, so the cart can be kept for later.
5. A user adds a book to the cart, closes the browser, and reopens it. The cart is now empty. Which cookie was most likely used?
A. A persistent cookie
B. A session cookie ✓
Session cookies are deleted when the browser closes, so the cart is lost. A persistent cookie would have kept it.

Match the Pairs

Set-Cookie: cart=pencil,ruler → The server tells the browser to store a cookie named cart that remembers the items the user added to their shopping cart.
Set-Cookie: cart=book; Max-Age=604800 → A persistent shopping cart cookie that keeps the cart for 7 days, so the items are still there when the user returns later.
A session cookie suits one shopping visit because it is deleted when the browser is closed. → Set-Cookie: cart=shoes
A persistent cookie keeps a cart for later because it stays stored until its expiry date. → Set-Cookie: cart=shoes; Max-Age=86400
Page 1: cart=hat. Page 2: no cookie sent, cart is empty → The browser did not send the cart cookie back to the server on page 2, so the server forgot the item. The cookie must be sent with each request so the cart survives moving between pages.
A persistent cookie is used for a cart on a shared school computer to hold items for one visit → A session cookie is the better choice for one visit, because it is deleted when the browser closes. A persistent cookie would leave the cart stored for the next person to see.

Key Term

shopping cart cookie
A cookie that remembers which items a user has added to an online shopping cart, so the cart is not emptied as they move between pages. It can last one visit or be kept for later.

Fill in the Blanks

1. Set-Cookie: cart=item42
Hint: Type the name of the header a web server uses to tell the browser to store a cookie.
2. Set-Cookie: cart=item42; Max-Age=604800
Hint: Type the attribute that sets how long the cart cookie lasts, so it stays for later.
3. GET /basket.html HTTP/1.1 Cookie: cart=item42
Hint: Type the request header the browser uses to send the stored cart cookie back to the server.
4. Set-Cookie: cart=item42 # no Max-Age: a session cookie
Hint: Type the cookie type that suits one shopping visit and is deleted when the browser closes.
5. Set-Cookie: cart=item42; Max-Age=86400 # persistent: cart kept for later visits
Hint: Type the cookie type that keeps the cart after the browser is closed.

Spot the Error

Question 1
A INPUT item
B cart ← cart + item
C DELETE cart FROM cookie
D GO TO next page
Line C — The cart must be stored in the cookie so it survives the move to the next page. Deleting it would empty the cart. It should be STORE cart IN cookie.
Question 2
A cookie.type ← "session"
B cart ← READ cookie
C cart ← cart + "Shoes"
D WRITE "empty" TO cookie
Line D — Writing "empty" overwrites the cookie and loses the items. The updated cart, including the shoes, should be written back: WRITE cart TO cookie.
Question 3
A ON page load:
B cart ← []
C OUTPUT cart
Line B — Setting the cart to an empty list empties it on every new page. The page should read the saved cart from the cookie: cart ← READ cookie "cart".
Question 4
A // One shopping visit
B cookie.type ← "persistent"
C lasts ← "browser closed"
Line B — A cart for one shopping visit suits a session cookie, which is deleted when the browser closes. A persistent cookie would be kept longer than needed. It should be "session".
Question 5
A // Keep cart for next week
B cookie.type ← "session"
C cart ← READ cookie
D OUTPUT cart
Line B — A session cookie is deleted when the browser closes, so the cart would be lost. To keep the cart for later, use a persistent cookie: cookie.type ← "persistent".

Student with a class code? Join your class →