0
0
PHPprogramming~5 mins

How sessions work in PHP - Quick Revision & Summary

Choose your learning style9 modes available
Recall & Review
beginner
What is a session in PHP?
A session in PHP is a way to store information (variables) to be used across multiple pages by the same user. It helps keep data like login status or preferences while the user browses the website.
Click to reveal answer
beginner
How does PHP identify a user session?
PHP uses a unique session ID stored in a cookie on the user's browser. This ID links the user to their stored session data on the server.
Click to reveal answer
beginner
What function starts a session in PHP?
The function session_start() starts a new session or resumes an existing one. It must be called before any output is sent to the browser.
Click to reveal answer
intermediate
Where does PHP store session data?
PHP stores session data on the server, usually in temporary files. The session ID in the user's cookie tells PHP which data belongs to that user.
Click to reveal answer
beginner
How do you store and access session variables in PHP?
Use the $_SESSION superglobal array. For example, $_SESSION['username'] = 'Alice'; stores data, and you can access it later with $_SESSION['username'].
Click to reveal answer
Which PHP function is used to start or resume a session?
Ainit_session()
Bstart_session()
Cbegin_session()
Dsession_start()
Where is the session ID usually stored on the client side?
AIn the URL only
BIn a cookie
CIn a hidden form field
DIn local storage
What superglobal array holds session variables in PHP?
A$_SESSION
B$_POST
C$_GET
D$_COOKIE
When must session_start() be called in a PHP script?
AOnly on the login page
BAfter HTML content is sent
CBefore any output is sent to the browser
DAt the end of the script
Where is session data stored in PHP?
AOn the server
BIn the user's browser
CIn the database only
DIn the URL
Explain how PHP uses sessions to remember user information across pages.
Think about how PHP links a user to their data using a unique ID.
You got /5 concepts.
    Describe the steps to store and retrieve a username using PHP sessions.
    Remember the order and the special array used.
    You got /3 concepts.