Recall & Review
beginner
What is a cookie in web development?
A cookie is a small piece of data stored on the user's computer by the web browser. It helps websites remember information about the user, like login status or preferences.
Click to reveal answer
beginner
How do you set a cookie in PHP?
You use the
setcookie() function. For example: setcookie('user', 'Alice', time() + 3600); sets a cookie named 'user' with value 'Alice' that expires in 1 hour.Click to reveal answer
beginner
How do you read a cookie value in PHP?
You read cookies from the
$_COOKIE superglobal array. For example: $user = $_COOKIE['user'] ?? 'Guest'; gets the 'user' cookie or 'Guest' if it doesn't exist.Click to reveal answer
intermediate
What must you remember about when to call
setcookie() in PHP?You must call
setcookie() before any output is sent to the browser, because it sends HTTP headers. If you print or echo anything first, setting cookies will fail.Click to reveal answer
intermediate
How can you delete a cookie in PHP?
To delete a cookie, set it with an expiration time in the past. For example:
setcookie('user', '', time() - 3600); tells the browser to remove the 'user' cookie.Click to reveal answer
Which PHP function is used to set a cookie?
✗ Incorrect
The correct function to set a cookie in PHP is
setcookie().Where are cookies stored?
✗ Incorrect
Cookies are stored on the user's computer by the web browser.
How do you access a cookie named 'session' in PHP?
✗ Incorrect
Cookies are accessed using the
$_COOKIE array, like $_COOKIE['session'].What happens if you call
setcookie() after outputting HTML?✗ Incorrect
Cookies require HTTP headers, so calling
setcookie() after output causes failure.How do you delete a cookie named 'user'?
✗ Incorrect
To delete a cookie, set it with an expiration time in the past using
setcookie().Explain how to set and read a cookie in PHP with an example.
Think about how you tell the browser to save data and then how you get it back.
You got /3 concepts.
What are the important rules to remember when working with cookies in PHP?
Consider timing and how cookies expire or get removed.
You got /3 concepts.