Teachers' Portal  /  IGCSE Computer Science 0478  /  The internet and its uses  /  Session and persistent cookies
Lesson pack · IGCSE Computer Science 0478 · 5.1 · IGCSE

Session and persistent cookies

Websites that remember. Add a jacket to your basket, click to another page, and the jacket is still there.

Student lesson Lab, full screen
At a glance

The shape of the lesson

Topic
The internet and its uses
Syllabus reference
Cambridge IGCSE Computer Science 0478, 5.1
Level
IGCSE
Duration
45 minutes, lab-led; stretches to a 60 minute block (see the contingency notes)
Position in topic
Lesson 4 of 7 in The internet and its uses; follows How a web page is located and retrieved: DNS; leads into Digital currency and blockchain
Central model
Fig. 1: a session cookie ends with the browser session; a persistent cookie lasts until it expires
Cooperative structure
Assessment
Stage 1 check and the exam-style plenary from the student lesson, plus the worksheet as the exit task
Learning objectives

By the end of the lesson, learners can

Section by section
  • What a cookie is: HTTP on its own does not remember anything between one request and the next.
  • Session or persistent?: The difference is how long the cookie lasts, which decides what it can be used for.
  • What cookies are used for: The syllabus names four uses.
Key points to leave on the board
  • Cookie: small text file sent by a website, stored by the browser on the user's device.
  • Session: temporary memory; deleted when the browser is closed.
  • Persistent: hard drive; kept until it expires or is deleted.
  • Uses: personal details, preferences, shopping cart, login details.
The core visual model

One picture every idea returns to

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.

how long each type of cookie lasts time browser closed session deleted when the browser closes persistent saved on the hard drive until expiry
Fig. 1: a session cookie ends with the browser session; a persistent cookie lasts until it expires
Lesson sequence

Forty-five minutes, phase by phase

TimePhaseWhat happens in the roomGrouping
0 to 5 minHook: predictOpen with the question in the title, Websites that remember.. Add a jacket to your basket, click to another page, and the jacket is still there. Put the figure on the board: it is the one picture every idea in the lesson returns to.Whole class, then pairs
5 to 13 minTeach and check: What a cookie isHTTP on its own does not remember anything between one request and the next. Project tab 2 of the lab (Session and persistent cookies) and let a student drive it while the class predicts.Whole class, then pairs
13 to 21 minTeach and check: Session or persistent?The difference is how long the cookie lasts, which decides what it can be used for.Pairs
21 to 30 minTeach and check: What cookies are used forThe syllabus names four uses. Model the worked example Pick the type on the board, one line at a time. Your turn: A news site shows every visitor's chosen language each time they return. Which type of cookie is used, and why?Frayer Model
30 to 36 minCheckThe four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong.Individual, then whole class
36 to 43 minPlenaryThe exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording.Individual, random call
43 to 45 minExit and homeworkSet the worksheet below (6 questions, 13 marks). Learners self-assess against the objectives before they leave.Individual
Timing and contingency

Protect the parts that carry the learning

The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.

Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.

Cut first if the build overruns: the last check in What cookies are used for, never the check or the plenary.

In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.

Running the cooperative task

Frayer Model

Pairs fill a four-box grid for the key term: definition, characteristics, examples and non-examples. The non-examples box is where the misconceptions surface, so give it the most time.

The full structure, with its variations and the other twelve, is on the cooperative-learning page.

Examiner traps to pre-empt

What to head off, and how

Trap learners fall intoTeaching move that pre-empts it
A session cookie is not deleted when the user leaves the page or the website.It is deleted when the browser is closed.
Worksheet

Session and persistent cookies: worksheet

6 questions, 13 marks. Written in the style of the papers; no past paper question is reproduced.

NameClassDate
Q1 · recall[2 marks]

State what is meant by a cookie.

Q2 · explain[2 marks]

Explain the difference between a session cookie and a persistent cookie.

Q3 · recall[3 marks]

Identify three ways that cookies are used by websites.

Q4 · apply[2 marks]

An online shop wants customers to stay logged in for 30 days, even after they turn off their computer. Identify the type of cookie needed and explain your choice.

Q5 · explain[2 marks]

Explain how a cookie allows a website to keep items in a shopping cart as the user moves between pages.

Q6 · analysis[2 marks]

A student says that cookies are dangerous because they can run on your computer and delete files. Evaluate this statement.

Answer key and marking notes
Q1 · 2 marks
  • A small text file sent by a web server / website.
  • Stored by the web browser on the user's computer (holding data about the user's visit / preferences).
Q2 · 2 marks
  • A session cookie is stored in temporary memory and is deleted when the browser is closed.
  • A persistent cookie is stored on the hard drive and remains until its expiry date or until the user deletes it.
Q3 · 3 marks
  • Saving personal details.
  • Tracking user preferences.
  • Holding items in an online shopping cart / storing login details (any one).
Q4 · 2 marks
  • A persistent cookie.
  • Because it is stored on the hard drive with an expiry date (30 days), so it is not deleted when the browser is closed or the computer turned off.
Q5 · 2 marks
  • The website stores the cart contents / an ID for the cart in a cookie on the user's device.
  • The browser sends the cookie with each new page request, so the server can recognise the user and show the same cart.
Q6 · 2 marks
  • Incorrect: cookies are small text files (data), not programs, so they cannot run or delete files.
  • However, persistent cookies can track users' browsing / preferences, which raises privacy concerns.
Quiz

6 multiple-choice questions on this lesson

From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.

Q11 mark

What is a cookie?

  • AA small text file sent by a web server and stored by the browser on the user's device
  • BA small program that runs on the user's computer when a page opens
  • CA record on the DNS of every website a user has visited
  • DA type of malware that copies a user's keystrokes
Q21 mark

When is a session cookie deleted?

  • AWhen the browser is closed
  • BWhen the user moves to a different page
  • COn its expiry date, which may be months away
  • DOnly when the user deletes it by hand
Q31 mark

Each time a user returns to a weather website it shows temperatures in degrees Celsius, which the user chose on a previous visit. Which type of cookie is being used?

  • AA persistent cookie tracking the user's preferences
  • BA session cookie holding the user's shopping cart
  • CA session cookie that is deleted when the page closes
  • DNo cookie: the web server remembers the user's IP address
Q41 mark

A user adds three books to a basket on an online shop, then moves between several pages before paying. The site does not need to remember the basket after this visit. Which cookie is most suitable?

  • AA session cookie
  • BA persistent cookie with a one-year expiry date
  • CA cookie stored on the DNS
  • DA cookie stored in the router
Q51 mark

A music website wants users who tick "Remember me" to stay logged in for 30 days, even after switching their computer off. Which statement explains the right choice?

  • AA persistent cookie, because it is stored on the hard drive with an expiry date 30 days ahead
  • BA session cookie, because it is kept until the user next logs out
  • CA persistent cookie, because it is stored in RAM, which keeps data when the power is off
  • DA session cookie, because it is deleted after exactly 30 days
Q61 mark

A student says: "Cookies are dangerous because they can run on your computer and delete your files." Which is the best evaluation?

  • AWrong, because cookies are text files that cannot run; but persistent cookies can track browsing, which raises privacy concerns
  • BCorrect, because every cookie is a program that the browser runs when a page opens
  • CWrong, because cookies are deleted the moment they reach the computer
  • DCorrect, because session cookies are a type of virus that attaches itself to files
Quiz key
Q1: A

A cookie is a small text file created by the website and kept by the browser, then sent back with later requests so the site recognises the user. It is not a program, so it cannot run. The DNS stores domain names and IP addresses, not users' visits, and recording keystrokes is what spyware does.

Q2: A

Session cookies are held in temporary memory and are deleted when the browser is closed. They survive moving between pages, which is why a basket is kept while shopping. An expiry date months away, or lasting until the user deletes it, describes a persistent cookie.

Q3: A

The preference has to be remembered from one visit to the next, so it is stored in a persistent cookie on the hard drive until it expires. Session cookies are deleted when the browser closes, so they could not remember it, and there is no shopping cart here. Relying on the IP address is unreliable because many users share or change IP addresses; cookies are how sites recognise returning users.

Q4: A

A session cookie keeps the basket while the user moves between pages and is deleted when the browser closes, which is all that is needed here. A persistent cookie would keep the data long after it was needed. Cookies are stored by the browser on the user's device, not on a DNS or router.

Q5: A

A persistent cookie is saved in secondary storage (the hard drive), so it survives the computer being turned off, and its expiry date can be set to 30 days. A session cookie is deleted when the browser closes, whatever the user does. RAM is volatile, so it loses data when the power is off, and session cookies have no 30-day expiry.

Q6: A

Cookies are small text files holding data, so they cannot execute or delete files. The real concern is privacy: persistent cookies can track what a user looks at across visits. Cookies are not programs or viruses, and they are kept (until the browser closes or they expire), not deleted on arrival.

Lab and demo

What to project

The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.

Slides

Slides for this lesson

A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.

Also for this topic

Everything else you can use

Original work by the TheLucidSTEM team. The worksheet items are written in the style of the papers; no past paper question is reproduced.
Previous lessonHow a web page is located and retrieved: DNS