Operating System Information in $_SERVER
<< Retrieving Information from HTTP Requests
<< PHP Tutorials - Herong's Tutorial Examples
This section provides a tutorial example on how to dump operating system information stored in the $_SERVER array.
To help us understand how predefined variables, $_GET, $_POST, $_COOKIE, $_REQUEST, and $_SERVER, work, I wrote the following tutorial example script:
<?php # HttpRequestDetails.php # Copyright (c) 2002 by Dr. Herong Yang, http://www.herongyang.com/ # print "<pre>\n"; print "\nContents of \$_GET:\n"; foreach ($_GET as $k => $v) { print " $k = $v\n"; } # print "\nContents of \$_POST:\n"; foreach ($_POST as $k => $v) { print " $k = $v\n"; } # print "\nContents of \$_COOKIE:\n"; foreach ($_COOKIE as $k => $v) { print " $k = $v\n"; } # print "\nContents of \$_REQUEST:\n"; foreach ($_REQUEST as $k => $v) { print " $k = $v\n"; } # print "\nContents of \$_SERVER:\n"; foreach ($_SERVER as $k => $v) { print " $k = $v\n"; } print "</pre>\n"; ?>
If you run this example script standalone without using any Web server, you should get:
<pre> Contents of $_GET: Contents of $_POST: Contents of $_COOKIE: Contents of $_REQUEST: Contents of $_SERVER: CLIENTNAME = Console ComSpec = C:\WINDOWS\system32\cmd.exe HOMEDRIVE = C: PHPRC = c:\php PROCESSOR_ARCHITECTURE = x86 SESSIONNAME = Console SystemDrive = C: SystemRoot = C:\WINDOWS PHP_SELF = HttpRequestDetails.php SCRIPT_NAME = HttpRequestDetails.php SCRIPT_FILENAME = HttpRequestDetails.php PATH_TRANSLATED = HttpRequestDetails.php DOCUMENT_ROOT = argv = Array argc = 1 ...... </pre>
Note that $_GET, $_POST, $_COOKIE, and $_REQUEST are all empty, because we executed the script without any HTTP request. $_SERVER contains only information gathered from the operating system.
Last update: 2005.
Sections in This Chapter
Predefined Variables Related to HTTP Requests
Web Server Information in $_SERVER
Information in $_GET and $_REQUEST
Registering $_REQUEST Keys as Global Variables