PHP Predefined Variables

← Back to Index


Predefined Variable 1: $_SERVER

$_SERVER is automatically populated by PHP with information about the server environment and the current HTTP request.

Key Value What It Means
$_SERVER['PHP_SELF']/infost440/a3/predefined.phpThe filename of the currently executing script
$_SERVER['SERVER_NAME']brough27.soisweb.uwm.eduThe hostname of the server
$_SERVER['REQUEST_METHOD']GETThe HTTP method used (GET or POST)
$_SERVER['SERVER_PORT']443The port the server is listening on
$_SERVER['SERVER_SOFTWARE']ApacheThe server software and version

Predefined Variable 2: REMOTE_ADDR & HTTP_USER_AGENT

These keys reveal information about the visitor making the request.

echo $_SERVER['REMOTE_ADDR'];     // Visitor IP address
echo $_SERVER['HTTP_USER_AGENT']; // Visitor browser and OS
    

REMOTE_ADDR: 216.73.216.9 — The IP address of the visitor.

HTTP_USER_AGENT: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com) — The visitor's browser and operating system.


Explanation

PHP's predefined variables, also called superglobals, are built-in variables that PHP automatically creates and populates at the start of every request. They are available in every scope of every script including inside functions and classes without needing any special declaration. You do not create or initialize them — PHP handles that automatically based on the server environment and incoming HTTP data. Examples include $_SERVER (server and request info), $_GET (URL query parameters), $_POST (form submission data), $_SESSION (session data), and $_COOKIE (browser cookies). These superglobals are essential for building dynamic web applications because they give PHP direct access to who is visiting and how they sent data.

INFOST 440 — Activity 3 — Nyla Broughton