PHP Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 3.00

Web Server Information in $_SERVER

This section provides a tutorial example on how to dump Web server information stored in the $_SERVER array.

Now, let's run HttpRequestDetails.php on the local IIS Web server. First copy HttpRequestDetails.php to \inetpub\wwwroot, then run Internet Explorer (IE) with http://localhost/HttpRequestDetails.php. You should get:


Contents of $_GET:

Contents of $_POST:

Contents of $_COOKIE:

Contents of $_REQUEST:

Contents of $_SERVER:
   CONTENT_LENGTH = 0
   GATEWAY_INTERFACE = CGI/1.1
   HTTP_ACCEPT = */*
   HTTP_ACCEPT_LANGUAGE = en-us
   HTTP_CONNECTION = Keep-Alive
   HTTP_HOST = localhost
   HTTP_ACCEPT_ENCODING = gzip, deflate
   HTTPS = off
   INSTANCE_ID = 1
   LOCAL_ADDR = 127.0.0.1
   NUMBER_OF_PROCESSORS = 1
   OS = Windows_NT
   ProgramFiles = C:\Program Files
   REMOTE_ADDR = 127.0.0.1
   REMOTE_HOST = 127.0.0.1
   REQUEST_METHOD = GET
   SCRIPT_NAME = /HttpRequestDetails.php
   SERVER_NAME = localhost
   SERVER_PORT = 80
   SERVER_PORT_SECURE = 0
   SERVER_PROTOCOL = HTTP/1.1
   SystemDrive = C:
   ORIG_PATH_INFO = /HttpRequestDetails.php
   ORIG_SCRIPT_NAME = /HttpRequestDetails.php
   DOCUMENT_ROOT = c:/inetpub/wwwroot
   SCRIPT_FILENAME = c:\inetpub\wwwroot\HttpRequestDetails.php
   PHP_SELF = /HttpRequestDetails.php
   ......

Note that $_GET, $_POST, $_COOKIE, and $_REQUEST are still all empty, because HTTP request contains no information submitted using the GET or POST method. And there is no cookies in the HTTP request.

However, other information contained in the HTTP request and gathered from the Web server is stored in the $_SERVER array now. For example, "DOCUMENT_ROOT = c:/inetpub/wwwroot" is piece of information from the Web server telling us that the Web server picks up HTTP documents and scripts from the c:/inetpub/wwwroot directory.

Last update: 2005.

Sections in This Chapter

Predefined Variables Related to HTTP Requests

Operating System Information in $_SERVER

Web Server Information in $_SERVER

Information in $_GET and $_REQUEST

Registering $_REQUEST Keys as Global Variables

Dr. Herong Yang, updated in 2009
Web Server Information in $_SERVER