Data from a GET request is stored in the superglobal $_GET
in the form of an associative array.
Note that accessing a non-existent array item generates a notice, so existence should always be checked with the isset()
or empty()
functions, or the null coalesce operator.
Example: (for URL /topics.php?author=alice&topic=php
)
$author = isset($_GET["author"]) ? $_GET["author"] : "NO AUTHOR";
$topic = isset($_GET["topic"]) ? $_GET["topic"] : "NO TOPIC";
echo "Showing posts from $author about $topic";
$author = $_GET["author"] ?? "NO AUTHOR";
$topic = $_GET["topic"] ?? "NO TOPIC";
echo "Showing posts from $author about $topic";