Search notes:

PHP code snippets: The $_SERVER super global variable

The following script iterates over the keys of the super global variable $_SERVER and displays the keys and values in a <table>.
<html>
<head><title>$_SERVER</title></head>
<body>

<table summary='_$SERVER key/values'>

<?php

ksort($_SERVER);
foreach ($_SERVER as $key => $value) {

  if ($key != 'argc' and $key != 'argv') {
     print "<tr><td>$key</td><td>" . htmlspecialchars($value) . "</td></tr>";
  }

}

?>
</table>


<p><a href='_SERVER.html?foo=bar'>Show HTTP_REFERRER and QUERY_STRING</a>


<form method="post">
  <input name="foo" value="bar">
  <input type="submit" value="Try POST method">
</form>


<p>Also use these links:
    <a href='_SERVER.html'>_SERVER.html</a>,
    <a href='_SERVER.html/some/inexisting/path'>_SERVER/some/inexisting/path</a>,
    <a href='_SERVER.html?foo=bar'>_SERVER.html?foo=bar</a>

</body>
</html>
Github repository about-php, path: /_SERVER.html
The script might produce something like. The special keys argv (which is an array and argv (whose value corresponds to the number of elements in argc) are already omitted in the script.
Key Possible value Comment or link
CONTENT_LENGTH 13
CONTENT_TYPE application/x-www-form-urlencoded
DOCUMENT_ROOT /home/httpd/vhosts/renenyffenegger.ch/httpsdocs
GATEWAY_INTERFACE CGI/1.1
HTTPS on
HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_ACCEPT_CHARSET ? Still used or populated?
HTTP_ACCEPT_ENCODING gzip, deflate, br
HTTP_ACCEPT_LANGUAGE en-US,en;q=0.5
HTTP_CONNECTION close
HTTP_HOST renenyffenegger.ch
HTTP_ORIGIN https://renenyffenegger.ch
HTTP_REFERER https://renenyffenegger.ch/code-snippets/about-php/_SERVER.html
HTTP_UPGRADE_INSECURE_REQUESTS 1
HTTP_USER_AGENT Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0 browser's User Agent String.
HTTP_X_ACCEL_INTERNAL /internal-nginx-static-location
HTTP_X_FORWARDED_HOST ? Still used or populated?
HTTP_X_REAL_IP 31.10.132.112
ORIG_PATH_INFO /code-snippets/about-php/_SERVER.html
ORIG_PATH_TRANSLATED /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/code-snippets/about-php/_SERVER.html
ORIG_SCRIPT_FILENAME /var/www/cgi-bin/cgi_wrapper/cgi_wrapper
ORIG_SCRIPT_NAME /phppath/cgi_wrapper
PATH /usr/local/bin:/usr/bin:/bin getenv("PATH")
PATH_TRANSLATED ? Still used or populated?
PHP_AUTH_PW ? Still used or populated?
PHP_AUTH_USER ? Still used or populated?
PHP_SELF /code-snippets/about-php/_SERVER.html
QUERY_STRING foo=bar&x=7
REDIRECT_STATUS 200
REDIRECT_URL /code-snippets/about-php/_SERVER.html
REMOTE_ADDR aaa.bbb.ccc.ddd
REMOTE_PORT 38984
REMOTE_HOST Still used or populated?
REQUEST_METHOD POST HTTP request methods
REQUEST_TIME 1586501005 Unix time (seconds since January 1st, 1970 in UTC.
REQUEST_TIME_FLOAT 1586501005.626
REQUEST_URI /code-snippets/about-php/_SERVER.html URI
SCRIPT_FILENAME /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/code-snippets/about-php/_SERVER.html __FILE__
SCRIPT_NAME /code-snippets/about-php/_SERVER.html
SERVER_ADDR eee.fff.ggg.hhh
SERVER_ADMIN noreply@foobar.baz
SERVER_NAME renenyffenegger.ch
SERVER_PORT 443
SERVER_PROTOCOL HTTP/1.0
SERVER_SOFTWARE Apache
UNIQUE_ID XpAVjUI8jWNsZJlazOMUogAAAAg

See also

urldecode() might be used to decode percent encoded URIS in $_SERVER['QUERY_STRING'].
The DocumentRoot directive in a httpd.conf file.
$_SERVER['SERVER_SIGNATURE'] is returned in an <address> element.
Other PHP snippets.

Index