The built-in global variable $_SERVER contains a collection of information that is relevant to the processing environment. This hashtable has many different keys which are described in details below.
| Hash Key Name | Description |
|---|---|
| PHP_SELF | This variable holds the complete name of the script currently being run on the server. This will look something like /path/to/folder/page.php. |
| argv | This variable is only present when you run a PHP script from the command line. It contains an array of command line arguments the same way the C programming languages uses argv. |
| argc | This variable is only present when you run a PHP script from the command line. It contains the count of total command line parameters passed to the program. |
| GATEWAY_INTERFACE | Contains the version of the common gateway interface (CGI) supported by the current environment (web server). |
| SERVER_ADDR | The IP address of the server from which the web page is being served. Useful when used on a website hosted on an array of load-balanced web servers. |
| SERVER_NAME | The name of the web server that the script is being run on (web page is being loaded from). |
| SERVER_SOFTWARE | The name of the web server software that the website is using. Usually something like Apache or IIS. |
| SERVER_PROTOCOL | Gives the name and the version of the protocol used to access the web page. Usually this will be something like: HTTP/1.1 |
| REQUEST_METHOD | The type of request made to the web server to retrieve the web page. This will be one of: GET, POST, HEAD, or PUT. |
| REQUEST_TIME | The timestamp when the request was first received. Only available with PHP version 5.10 or later. |
| QUERY_STRING | The raw query string passed to the page. Basically the portion of the address or location starting with the question mark (?) to the end of the URI. |
| DOCUMENT_ROOT | The physical path to the home directory for the website. This is a complete path from the root of the filesystem. On Unix, this may look something like /var/www/something.com/. |
| HTTP_ACCEPT | Contains the different protocols the client browser is capable of using. This may be blank since some browsers don't report this (use with caution.) |
| HTTP_ACCEPT_CHARSET | Contains a comma-delimited list of character encodings (e.g.: UTF-8) the client browser accepts. In many cases, this is just left blank meaning that all character encodings are accepted. |
| HTTP_ACCEPT_ENCODING | The type of content encodings (e.g.: gzip) which are acceptable to the client browser |
| HTTP_ACCEPT_LANGUAGE | A comma-delimited list of language codes (e.g.: en) that the client browser accepts. |
| HTTP_CONNECTION | The HTTP connection properties (e.g.: Keep-Alive) that the browser accepts. |
| HTTP_HOST | The name of the host computer (client machine) which initiated the browser request. |
| HTTP_REFERER | The web page that referred the request. Basically, this is where the request came from (like the web page where a hyperlink was clicked.) This header is intentionally mis-spelled. |
| HTTP_USER_AGENT | The name of the software the client web browser is running (should be something like MSIE Microsoft Internet Explorer 6.5. |
| HTTPS | Contains a non-empty value if the script was accessed using the HTTPS (secure HTTP) protocol. |
| REMOTE_ADDR | The IP address of the remote user (client machine) which is accessing the web page. |
| REMOTE_HOST | The name of the client machine which is accessing the web page. |
| REMOTE_PORT | The IP port number the user is using the access the web page (usually port 80 for HTTP protocol). |
| SCRIPT_FILENAME | The absolute pathname for the web page on the web server. This is a complete path from the root of the filesystem (e.g.: /var/www/somedomain.com/http/index.php). |
| SERVER_ADMIN | The name of the web server administrator as configured in the configuration file. |
| SERVER_PORT | An integer representing the communications port used to send the response to the client. |
| SERVER_SIGNATURE | A string which identifies the server or virtual host being accessed by the web request. |
| PATH_TRANSLATED | The absolute path and filename for the web resource that was requested. This is based off of the root of the filesystem (e.g.: /var/www/somedomain.com/http/index.php). |
| SCRIPT_NAME | The path and web page name for the currently running script. Useful for creating a script that references itself (e.g.: form that posts to itself). |
| REQUEST_URI | The URL which was used to access the web page. |
| PHP_AUTH_DIGEST | If your Apache web server is configured to perform Digest HTTP Authorization, this variable holds the authorization header sent in the web request. |
| PHP_AUTH_USER | If you have password-protected your site or a directory on your site using Basic Autentication, you may use this variable to get the username used to access the site. Useful when more than one username and password may be used to access the web server. |
| PHP_AUTH_PW | If you have password-protected your site or a directory on your site using Basic Autentication, this variable holds the password used to access the web server. |
| AUTH_TYPE | If your website requires authorization, this variable will hold the type of authorization check performed on the user. |
// output the script currently being run echo $_SERVER['PHP_SELF']; // output all of the server variables foreach ($_SERVER as $k=>$v) echo $k . ' = ' . htmlspecialchars($v) . '<br>';