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. It helps keep user data while they browse a website.
Click to reveal answer
beginner
How do you start a session in PHP?
Use the function
session_start(); at the very beginning of your PHP script before any output. This creates or resumes a session.Click to reveal answer
beginner
How do you store data in a PHP session?
You store data by assigning values to the
$_SESSION superglobal array, like $_SESSION['key'] = 'value';.Click to reveal answer
beginner
How do you access session data on another page?
First, call
session_start(); on the page, then read the data from $_SESSION['key'].Click to reveal answer
intermediate
What must you avoid before calling
session_start();?You must avoid sending any output (like HTML or echo) before
session_start(); because it sends HTTP headers.Click to reveal answer
Which PHP function starts or resumes a session?
✗ Incorrect
The correct function to start or resume a session in PHP is
session_start().Where should
session_start() be placed in your PHP script?✗ Incorrect
session_start() must be called before any output to avoid header errors.How do you store a user's name in a session variable?
✗ Incorrect
Use the superglobal array
$_SESSION to store session data like $_SESSION['name'] = 'John';.What happens if you try to access
$_SESSION without calling session_start()?✗ Incorrect
Without
session_start(), PHP does not load session data, so $_SESSION will be empty or cause errors.Which superglobal array holds session variables?
✗ Incorrect
Session variables are stored in the
$_SESSION superglobal array.Explain how to start a session and store a user's favorite color in PHP.
Remember to start the session first, then save data in $_SESSION.
You got /4 concepts.
Describe why it is important to call session_start() before any output in PHP.
Think about how PHP sends session cookies in headers.
You got /4 concepts.