PHP Predefined Variables

Example 1: $_SERVER

$_SERVER['REQUEST_METHOD'] is GET. It tells us which HTTP method, such as GET, was used to request this page.

Example 2: $_GET

$_GET['topic'] is Cybersecurity. It gets the topic parameter from the page's URL. Try a different topic.

Explanation

Predefined variables are supplied by PHP, so I do not have to create them before reading them. These two are superglobal arrays, meaning I can access them throughout a script. $_SERVER provides information about the web request and server. $_GET contains values from a URL's query string, which a visitor can change, so I escape its output.

Back to Activity 3