Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q13 of 15
PHP - Sessions and Cookies
What will be the output of this PHP code?
<?php
session_start();
$_SESSION['user'] = 'Alice';
echo $_SESSION['user'];
?>
Auser
BAlice
CArray
DUndefined index error
Step-by-Step Solution
Solution:
  1. Step 1: Start session and assign value

    The code starts a session and sets the session variable 'user' to 'Alice'.
  2. Step 2: Output the session variable

    Using echo $_SESSION['user']; prints the value stored, which is 'Alice'.
  3. Final Answer:

    Alice -> Option B
  4. Quick Check:

    $_SESSION['user'] = 'Alice' outputs Alice [OK]
Quick Trick: Session variables store values like arrays [OK]
Common Mistakes:
  • Expecting 'user' instead of its value
  • Forgetting to call session_start() first
  • Confusing session variables with regular variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes