Bird
0
0

How do you correctly assign the value "John" to a session variable named user in PHP?

easy📝 Syntax Q3 of 15
PHP - Sessions and Cookies
How do you correctly assign the value "John" to a session variable named user in PHP?
Asession_set('user', "John");
B$_SESSION['user'] = "John"; session_start();
Cset_session('user', "John");
Dsession_start(); $_SESSION['user'] = "John";
Step-by-Step Solution
Solution:
  1. Step 1: Start the session

    Call session_start() before accessing session variables.
  2. Step 2: Assign the session variable

    Use $_SESSION['user'] = "John"; to set the value.
  3. Final Answer:

    session_start(); $_SESSION['user'] = "John"; -> Option D
  4. Quick Check:

    Session must be started before setting variables [OK]
Quick Trick: Always call session_start() before using $_SESSION [OK]
Common Mistakes:
  • Assigning session variables before calling session_start()
  • Using non-existent functions like set_session()
  • Confusing session_set() with session_start()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes