Persistent cookies

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

Persistent cookies

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What happens to a persistent cookie when the browser is closed?
A It stays saved on the device
B It is deleted straight away
2. When is a persistent cookie removed automatically?
A When the user closes the tab
B When its expiry date is reached
3. Where is a persistent cookie stored?
A On the hard drive of the user's device
B Only in the computer's temporary memory (RAM)
4. A user visits a website, closes the browser, then visits the same website the next day. What happens to the persistent cookie?
A The website has forgotten it, so nothing is sent
B The browser sends it to the website again
5. Which statement about persistent cookies is true?
A They have an expiry date set
B They never have an expiry date

Match the Pairs

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

Left columnRight column
1Set-Cookie: user=Ava; Expires=Fri, 01 Jan 2027 00:00:00 GMT ASet-Cookie: lang=en; Expires=Sat, 30 Jun 2029 12:00:00 GMT
2Set-Cookie: theme=dark; Max-Age=2592000 BThis describes a session cookie. A persistent cookie stays on the device after the browser closes until its expiry date.
3A persistent cookie has an expiry date, so it is removed only when that date is reached or the user deletes it CPersistent cookies are stored on the hard drive and have an expiry date. Cookies held only in memory without an expiry date are session cookies.
4A persistent cookie is sent back to the web server on each later visit to the website, even after the browser was closed DKeeps the cookie for 30 days, then it is deleted, even if the browser has been closed in between
5A persistent cookie is deleted as soon as the browser is closed. EGET /home HTTP/1.1 Host: www.shop.com Cookie: user=Ava
6A persistent cookie is kept in RAM and has no expiry date. FCreates a persistent cookie that stays on the device until the expiry date given

Definitions

persistent cookie

Fill in the Blanks

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

1.
__________: id=42; Expires=01 Jan 2027
2.
Set-Cookie: id=42; _______=01 Jan 2027
3.
GET /shop HTTP/1.1 Host: www.shop.com ______: id=42
4.
IF today _ expiry THEN DELETE cookie ENDIF
5.
IF today < expiry THEN SEND cookie TO ______ ENDIF

Spot the Error

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

Question 1
A IF cookie has an expiry date
B THEN store in RAM only
C ENDIF
Question 2
A Visit 1: server sets cookie
B Browser is closed
C Cookie is deleted at once
D Visit 2: browser sends cookie
Question 3
A name ← "theme"
B value ← "dark"
C expires ← NONE
D SAVE cookie TO hard drive
Question 4
A Persistent cookie ends on exit
B It is saved on the hard drive
C It is sent again on next visit
Question 5
A Day 1: user ticks Remember me
B Site sets a persistent cookie
C Day 2: cookie is not sent
D Site recognises the user

Answer Key

Persistent cookies
Section A: Quick Questions
Q1
A — It stays saved on the device
Q2
B — When its expiry date is reached
Q3
A — On the hard drive of the user's device
Q4
B — The browser sends it to the website again
Q5
A — They have an expiry date set
Section B: Match the Pairs
Q1
Set-Cookie: user=Ava; Expires=Fri, 01 Jan 2027 00:00:00 GMT → Creates a persistent cookie that stays on the device until the expiry date given
Q2
Set-Cookie: theme=dark; Max-Age=2592000 → Keeps the cookie for 30 days, then it is deleted, even if the browser has been closed in between
Q3
A persistent cookie has an expiry date, so it is removed only when that date is reached or the user deletes it → Set-Cookie: lang=en; Expires=Sat, 30 Jun 2029 12:00:00 GMT
Q4
A persistent cookie is sent back to the web server on each later visit to the website, even after the browser was closed → GET /home HTTP/1.1 Host: www.shop.com Cookie: user=Ava
Q5
A persistent cookie is deleted as soon as the browser is closed. → This describes a session cookie. A persistent cookie stays on the device after the browser closes until its expiry date.
Q6
A persistent cookie is kept in RAM and has no expiry date. → Persistent cookies are stored on the hard drive and have an expiry date. Cookies held only in memory without an expiry date are session cookies.
Section C: Definitions
Q1
persistent cookie — A cookie saved on the device until its expiry date or until the user deletes it, so it stays after the browser closes and is sent again on later visits.
Section D: Fill in the Blanks
Q1
Set-Cookie: id=42; Expires=01 Jan 2027
Q2
Set-Cookie: id=42; Expires=01 Jan 2027
Q3
GET /shop HTTP/1.1 Host: www.shop.com Cookie: id=42
Q4
IF today > expiry THEN DELETE cookie ENDIF
Q5
IF today < expiry THEN SEND cookie TO server ENDIF
Section E: Spot the Error
Q1
B — A persistent cookie is saved on the hard drive so it survives after the browser closes. RAM is cleared, so it should say: THEN store on hard drive.
Q2
C — A persistent cookie is not deleted when the browser closes. It stays on the hard drive until its expiry date, so line 3 should say it stays.
Q3
C — A persistent cookie must have an expiry date. With no expiry date it would be a session cookie. It should be something like expires ← "01/01/2027".
Q4
A — A persistent cookie does not end when the browser is closed. It lasts until its expiry date, so the line should say it has an expiry.
Q5
C — A persistent cookie is sent again to the website on each later visit, so the site can recognise the user. It should say the cookie is sent again.