Bird
0
0

Identify the error in this PHP code snippet that tries to print the visitor's browser info:

medium📝 Debug Q14 of 15
PHP - Superglobals and Web Context
Identify the error in this PHP code snippet that tries to print the visitor's browser info:
echo $_SERVER[HTTP_USER_AGENT];
A$_SERVER cannot be echoed directly
BUsing wrong key name
CMissing quotes around the array key
DHTTP_USER_AGENT is not available in $_SERVER
Step-by-Step Solution
Solution:
  1. Step 1: Check array key syntax

    Array keys must be strings in quotes. Here, HTTP_USER_AGENT is missing quotes.
  2. Step 2: Confirm key existence

    HTTP_USER_AGENT is a valid key in $_SERVER, so the key name is correct.
  3. Final Answer:

    Missing quotes around the array key -> Option C
  4. Quick Check:

    Array keys need quotes [OK]
Quick Trick: Always quote $_SERVER keys like 'HTTP_USER_AGENT' [OK]
Common Mistakes:
  • Forgetting quotes around keys
  • Assuming key name is wrong
  • Trying to echo whole $_SERVER array directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes