Bird
0
0

You want to log the full URL a user requested, including query parameters. Which combination of $_SERVER variables should you use?

hard📝 Application Q8 of 15
PHP - Superglobals and Web Context
You want to log the full URL a user requested, including query parameters. Which combination of $_SERVER variables should you use?
A$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
B$_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']
C$_SERVER['REMOTE_ADDR'] . $_SERVER['QUERY_STRING']
D$_SERVER['SCRIPT_NAME'] . $_SERVER['REQUEST_METHOD']
Step-by-Step Solution
Solution:
  1. Step 1: Identify variables for full URL

    HTTP_HOST gives the domain, and REQUEST_URI gives the path plus query string.
  2. Step 2: Check other options

    SERVER_NAME is similar to HTTP_HOST but PHP_SELF lacks query string; REMOTE_ADDR is client IP, not URL; SCRIPT_NAME and REQUEST_METHOD do not form URL.
  3. Final Answer:

    $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] -> Option A
  4. Quick Check:

    Full URL = HTTP_HOST + REQUEST_URI [OK]
Quick Trick: Use HTTP_HOST plus REQUEST_URI for full URL [OK]
Common Mistakes:
  • Ignoring query parameters
  • Using client IP instead of host

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes