0
0
PHPprogramming~5 mins

How cookies work in PHP - Quick Revision & Summary

Choose your learning style9 modes available
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 does a server send a cookie to a browser in PHP?
The server sends a cookie using the setcookie() function before any output is sent. This function sets the cookie name, value, and optional parameters like expiration time.
Click to reveal answer
beginner
Where are cookies stored and how are they sent back to the server?
Cookies are stored in the user's browser. When the browser makes a request to the same server, it sends the stored cookies automatically in the HTTP headers.
Click to reveal answer
beginner
What is the purpose of the cookie expiration time?
The expiration time tells the browser how long to keep the cookie. If no expiration is set, the cookie lasts only for the browser session and is deleted when the browser closes.
Click to reveal answer
beginner
How can you access a cookie value in PHP?
You can access cookie values using the $_COOKIE superglobal array with the cookie's name as the key, for example, $_COOKIE['username'].
Click to reveal answer
Which PHP function is used to send a cookie to the browser?
Asetcookie()
Bcookie_send()
Csend_cookie()
Dcookie_set()
Where are cookies stored after being sent by the server?
AOn the user's browser
BOn the server
CIn the PHP script
DIn the database
What happens if you don't set an expiration time for a cookie?
AThe cookie is stored on the server
BThe cookie lasts forever
CThe cookie lasts only for the browser session
DThe cookie is deleted immediately
How do you access a cookie named 'user' in PHP?
Agetcookie('user')
B$_COOKIE['user']
Ccookie['user']
D$_SESSION['user']
When must you call setcookie() in a PHP script?
AOnly inside functions
BAfter HTML content is printed
CAnywhere in the script
DBefore any output is sent to the browser
Explain how cookies are created, stored, and sent back to the server in PHP.
Think about the journey of a cookie from server to browser and back.
You got /4 concepts.
    Describe the role of cookie expiration time and what happens if it is not set.
    Consider how long the cookie stays on the user's device.
    You got /3 concepts.