Bird
0
0

Given the URL site.com/index.php?category=books, how would you retrieve the value 'books' in PHP?

easy📝 Conceptual Q2 of 15
PHP - Superglobals and Web Context
Given the URL site.com/index.php?category=books, how would you retrieve the value 'books' in PHP?
Aecho $_REQUEST['category'];
Becho $_POST['category'];
Cecho $_GET['category'];
Decho $_SESSION['category'];
Step-by-Step Solution
Solution:
  1. Step 1: Identify the method to access URL parameters

    URL parameters are accessed using the $_GET superglobal.

  2. Step 2: Use correct syntax

    Access the parameter by its key: $_GET['category'].

  3. Final Answer:

    echo $_GET['category']; -> Option C
  4. Quick Check:

    URL parameters use $_GET, not $_POST or $_SESSION [OK]
Quick Trick: Use $_GET['param'] for URL parameters [OK]
Common Mistakes:
  • Using $_POST instead of $_GET
  • Confusing $_REQUEST with $_GET
  • Trying to access URL params via $_SESSION

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes