Choosing session or persistent cookies for a scenario

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

Choosing session or persistent cookies for a scenario

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A bank website lets you log in on a shared school computer. Which cookie type should it use?
A Persistent cookie, because it keeps you logged in for next time
B Session cookie, because it is deleted when the browser closes
2. A website remembers that you chose French as your language, and you want it to still be French in three months. Which cookie type fits?
A Persistent cookie, because the setting must last for later visits
B Session cookie, because the setting must last for later visits
3. An online shop only needs to hold your basket during one visit. Which is the better choice?
A Session cookie, because the basket is only needed until the visit ends
B Persistent cookie, because the basket is only needed until the visit ends
4. Which answer is better for an exam question that asks you to choose a cookie and justify it?
A Session cookie, because cookies are used on websites
B Session cookie, because the data is only needed until the browser closes
5. A user ticks 'Remember me' so they do not have to type their username again next week. Which cookie type is needed?
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: lang=fr; Max-Age=15552000 AThe cart is only needed during one visit, so it should be a session cookie. A persistent cookie that lasts 5 years is not needed and stores data for far too long.
2Set-Cookie: cart=Item42 Bcookie_type = "persistent" # language, months
3On a shared school computer, a bank login should use a session cookie because it is deleted when the browser closes and the next user cannot get in. CA session cookie: it has no expiry time, so it is deleted when the browser is closed.
4A website that remembers your language choice for months needs a persistent cookie because the setting must still be there on your next visit. DA persistent cookie stays on a shared computer after the browser closes, so the next person could use the account. A session cookie is the safe choice.
5Bank login on a library PC: use a persistent cookie because it is quicker next time. Ecookie_type = "session" # bank login, shared PC
6One-visit shopping cart: use a persistent cookie for 5 years. FA persistent cookie: it lasts about 6 months, so the language setting is remembered on later visits.

Definitions

session or persistent

Fill in the Blanks

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

1.
SCENARIO ← "bank login, shared computer" COOKIE ← "_______"
2.
SCENARIO ← "language setting for months" COOKIE ← "__________"
3.
SCENARIO ← "one-visit shopping cart" COOKIE ← "_______"
4.
IF NeededLater ____ COOKIE ← "persistent" ELSE COOKIE ← "session"
5.
Session _______ the cart is not needed later

Spot the Error

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

Question 1
A cookie ← "persistent"
B scenario ← "bank, shared PC"
C why ← "because it is deleted"
D OUTPUT cookie, why
Question 2
A need ← "language for months"
B lasts ← "many visits"
C IF lasts = "many visits" THEN
D cookie ← "session"
E ENDIF
Question 3
A scenario ← "language setting"
B cookie ← "session"
C why ← "because it is kept"
D OUTPUT cookie
Question 4
A scenario ← "language setting"
B lasts ← "for months"
C cookie ← "persistent"
D why ← "because it is deleted"
E OUTPUT cookie, why
Question 5
A scenario ← "bank, shared PC"
B lasts ← "for many visits"
C cookie ← "session"
D OUTPUT cookie

Answer Key

Choosing session or persistent cookies for a scenario
Section A: Quick Questions
Q1
B — Session cookie, because it is deleted when the browser closes
Q2
A — Persistent cookie, because the setting must last for later visits
Q3
A — Session cookie, because the basket is only needed until the visit ends
Q4
B — Session cookie, because the data is only needed until the browser closes
Q5
A — Persistent cookie
Section B: Match the Pairs
Q1
Set-Cookie: lang=fr; Max-Age=15552000 → A persistent cookie: it lasts about 6 months, so the language setting is remembered on later visits.
Q2
Set-Cookie: cart=Item42 → A session cookie: it has no expiry time, so it is deleted when the browser is closed.
Q3
On a shared school computer, a bank login should use a session cookie because it is deleted when the browser closes and the next user cannot get in. → cookie_type = "session" # bank login, shared PC
Q4
A website that remembers your language choice for months needs a persistent cookie because the setting must still be there on your next visit. → cookie_type = "persistent" # language, months
Q5
Bank login on a library PC: use a persistent cookie because it is quicker next time. → A persistent cookie stays on a shared computer after the browser closes, so the next person could use the account. A session cookie is the safe choice.
Q6
One-visit shopping cart: use a persistent cookie for 5 years. → The cart is only needed during one visit, so it should be a session cookie. A persistent cookie that lasts 5 years is not needed and stores data for far too long.
Section C: Definitions
Q1
session or persistent — Decide how long a cookie must last: session if it can go when the browser closes, persistent if it must last for later visits. Justify your choice with because.
Section D: Fill in the Blanks
Q1
SCENARIO ← "bank login, shared computer" COOKIE ← "session"
Q2
SCENARIO ← "language setting for months" COOKIE ← "persistent"
Q3
SCENARIO ← "one-visit shopping cart" COOKIE ← "session"
Q4
IF NeededLater THEN COOKIE ← "persistent" ELSE COOKIE ← "session"
Q5
Session because the cart is not needed later
Section E: Spot the Error
Q1
A — Line 1 is wrong. A bank login on a shared computer needs a session cookie, so the next user cannot get into the account after the browser closes. Line 1 should be cookie ← "session".
Q2
D — The setting must last for many visits, so the cookie must be persistent. A session cookie would be deleted when the browser closes and the language would be forgotten. Line 4 should be cookie ← "persistent".
Q3
B — A language setting must be remembered for months, so a persistent cookie is needed. A session cookie is deleted when the browser closes. Line 2 should be cookie ← "persistent".
Q4
D — The reason contradicts the choice. A persistent cookie is kept after the browser closes, it is not deleted. Line 4 should be why ← "because it is kept".
Q5
B — A bank login on a shared computer should only last until the browser closes. Saying it lasts for many visits would suggest a persistent cookie. Line 2 should be lasts ← "until browser closes".