Bird
0
0

What will be the output of this PHP code if a cookie named user is set to "Alice" and no GET or POST data is sent?

medium📝 Predict Output Q5 of 15
PHP - Superglobals and Web Context
What will be the output of this PHP code if a cookie named user is set to "Alice" and no GET or POST data is sent?
echo $_REQUEST['user'];
AAlice
BUndefined index error
CEmpty string
DNULL
Step-by-Step Solution
Solution:
  1. Step 1: Check sources in $_REQUEST

    Since no GET or POST data is sent, but a cookie named user exists, $_REQUEST will include it.
  2. Step 2: Output the cookie value

    Accessing $_REQUEST['user'] will output the cookie value "Alice".
  3. Final Answer:

    Alice -> Option A
  4. Quick Check:

    Cookies appear in $_REQUEST if no POST/GET override [OK]
Quick Trick: Cookies appear in $_REQUEST if no POST or GET override [OK]
Common Mistakes:
  • Expecting error if no GET/POST data
  • Thinking $_REQUEST excludes cookies

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes