Comparing session and persistent cookies

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Comparing session and persistent cookies

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A session cookie is deleted when you close the browser.
A True
B False
2. Which cookie stays on your device until its expiry date?
A Session cookie
B Persistent cookie
3. Where is a persistent cookie kept?
A On the user's device until it expires
B In the browser's memory only, until the browser closes
4. Which statement about cookies is correct?
A A cookie is a small piece of text data
B A cookie is a program that runs on your computer
5. Which cookie would keep an online shopping cart only while you are on the site?
A Persistent cookie
B Session cookie

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Set-Cookie: cart=3; Expires=Fri, 01 Jan 2027 AA persistent cookie: it has an expiry date, so it stays on the device after the browser closes until that date.
2Set-Cookie: sessionId=a81f BThis describes a session cookie. A persistent cookie is kept on the device until its expiry date, even after the browser closes.
3A session cookie is kept in temporary memory and is deleted as soon as the browser closes CA session cookie: it has no expiry date, so it is deleted when the browser is closed.
4A persistent cookie is stored on the device's storage and is kept until its expiry date Dlifetime = until expiry date
5A cookie is a program that can run on my computer Elifetime = until browser closes
6A persistent cookie is deleted when the browser closes FCookies are not programs. They are small text files or pieces of text data, so they cannot run or do things by themselves.

Definitions

session vs persistent cookie

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF browserClosed = TRUE THEN DELETE _______ cookie ENDIF
2.
IF today > expiryDate THEN DELETE __________ cookie ENDIF
3.
IF cookie.expiry = ____ THEN cookieType ← "session" ENDIF
4.
cookieIsProgram ← _____ cookieIsVirus ← FALSE cookieIsText ← TRUE
5.
IF cookieType = "persistent" THEN KEEP cookie UNTIL __________ ENDIF

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A // Session cookie
B Set-Cookie: basket=3
C On browser close: KEEP
D Cookie type: text data
Question 2
A // Persistent cookie
B Set-Cookie: a=1
C Closing browser: still stored
D Kept until expiry date
Question 3
A type <- 'persistent'
B expires <- '2027-01-01'
C stored <- 'temporary memory'
D OUTPUT type, stored
Question 4
A Cookies are small programs
B They cannot run or spread
C So they are not viruses
Question 5
A Session cookie lifetime:
B until the expiry date
C Persistent cookie lifetime:
D until the expiry date

Answer Key

Comparing session and persistent cookies
Section A: Quick Questions
Q1
A — True
Q2
B — Persistent cookie
Q3
A — On the user's device until it expires
Q4
A — A cookie is a small piece of text data
Q5
B — Session cookie
Section B: Match the Pairs
Q1
Set-Cookie: cart=3; Expires=Fri, 01 Jan 2027 → A persistent cookie: it has an expiry date, so it stays on the device after the browser closes until that date.
Q2
Set-Cookie: sessionId=a81f → A session cookie: it has no expiry date, so it is deleted when the browser is closed.
Q3
A session cookie is kept in temporary memory and is deleted as soon as the browser closes → lifetime = until browser closes
Q4
A persistent cookie is stored on the device's storage and is kept until its expiry date → lifetime = until expiry date
Q5
A cookie is a program that can run on my computer → Cookies are not programs. They are small text files or pieces of text data, so they cannot run or do things by themselves.
Q6
A persistent cookie is deleted when the browser closes → This describes a session cookie. A persistent cookie is kept on the device until its expiry date, even after the browser closes.
Section C: Definitions
Q1
session vs persistent cookie — A session cookie is deleted when the browser closes; a persistent cookie is kept on the device until it expires. Cookies are text data, not programs.
Section D: Fill in the Blanks
Q1
IF browserClosed = TRUE THEN DELETE session cookie ENDIF
Q2
IF today > expiryDate THEN DELETE persistent cookie ENDIF
Q3
IF cookie.expiry = NULL THEN cookieType ← "session" ENDIF
Q4
cookieIsProgram ← FALSE cookieIsVirus ← FALSE cookieIsText ← TRUE
Q5
IF cookieType = "persistent" THEN KEEP cookie UNTIL expiryDate ENDIF
Section E: Spot the Error
Q1
C — A session cookie is deleted when the browser closes. Line 3 should say DELETE, not KEEP.
Q2
B — A persistent cookie needs an expiry date. Without Expires or Max-Age it would be a session cookie. Line 2 should include Expires=2027.
Q3
C — A persistent cookie is kept on the device's storage (such as the hard drive) until it expires. Temporary memory is where session cookies are held.
Q4
A — Cookies are small pieces of text data, not programs. They cannot run code, so they are not viruses. Line 1 should say text files.
Q5
B — A session cookie lasts only until the browser closes. The expiry date is how long a persistent cookie lasts. Line 2 should be until the browser closes.