0
0
PHPprogramming~5 mins

Session variables in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a session variable in PHP?
A session variable is a way to store information (like user data) on the server for a user to use across multiple pages during their visit.
Click to reveal answer
beginner
How do you start a session in PHP?
You start a session by calling session_start(); at the very beginning of your PHP script before any output.
Click to reveal answer
beginner
How do you set a session variable in PHP?
After starting the session, you set a session variable like this: $_SESSION['key'] = 'value';
Click to reveal answer
beginner
How do you access a session variable in PHP?
After starting the session, you access a session variable by using $_SESSION['key'] to get its value.
Click to reveal answer
intermediate
Why do you need to call session_start() on every page that uses session variables?
Because session_start() tells PHP to resume the existing session or start a new one, so session variables are available on that page.
Click to reveal answer
What function do you use to begin a session in PHP?
Asession_start()
Bstart_session()
Cbegin_session()
Dinit_session()
Where are session variables stored?
AOn the server
BIn the user's browser cookies
CIn the HTML code
DIn a database automatically
How do you set a session variable named 'user' to 'Alice'?
Aset_session('user', 'Alice');
Bsession['user'] = 'Alice';
C$_SESSION['user'] = 'Alice';
Dsession->user = 'Alice';
What must you do before accessing any session variables on a page?
ACall session_access()
BCall session_start()
CInclude a session.php file
DNothing special is needed
Which superglobal array holds session variables in PHP?
A$_COOKIE
B$_GET
C$_POST
D$_SESSION
Explain how to create, store, and access a session variable in PHP.
Think about what you do at the start of the page and how you use the $_SESSION array.
You got /3 concepts.
    Why is it important to call session_start() on every page that uses session variables?
    Consider what happens if you try to use $_SESSION without starting the session.
    You got /3 concepts.