Intrax, Inc.

...located in Fairfax, VA

Print Apache Server Variables in PHP

Written by Joel McClung on February 27th, 2009

How did you print out the Apache server values in PHP? Grab the $_SERVER array and iterate through each value, like this:

<?php foreach($_SERVER as $key => $value) {
    echo $key . "=" . $value . "<br />\n";
};?>

Apache Web server variables

Written by Joel McClung on February 27th, 2009

Did you know that when you visit a web site, a certain amount of information is sent to the server? For example, for this session, the values the server has are below. If you visit this page from another computer, the results will be different.

The server can print this information or return it in the pages displayed. That’s how I’m able to print your IP address and hostname over on the right side of this site. The code I’m using is:

IP: <?php echo $_SERVER[REMOTE_ADDR];
echo "<br />";
echo $_SERVER[REMOTE_HOST];?>
(<a href="this_article">how</a>)

Server variables and their corresponding values:

REDIRECT_STATUS=200
HTTP_X_CC_LIST=List:1 For:216.194.210.194
HTTP_HOST=www.intrax.com
HTTP_USER_AGENT=CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
HTTP_ACCEPT=Accept: application/xhtml+xml,text/html;q=0.9,text/plain;
HTTP_ACCEPT_LANGUAGE=en-us,en;q=0.5
HTTP_ACCEPT_ENCODING=gzip
HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7
HTTP_CONNECTION=close
HTTP_CACHE_CONTROL=no-cache
HTTP_PRAGMA=no-cache
PATH=/usr/local/bin:/usr/bin:/bin
SERVER_SIGNATURE=
SERVER_SOFTWARE=Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8c DAV/2 PHP/5.2.5
SERVER_NAME=www.intrax.com
SERVER_ADDR=216.194.210.194
SERVER_PORT=80
REMOTE_ADDR=38.103.63.60
DOCUMENT_ROOT=/home/www/intrax/html
SERVER_ADMIN=webmaster@intrax.com
SCRIPT_FILENAME=/home/www/intrax/html/wordpress/index.php
REMOTE_PORT=47058
REDIRECT_URL=/
GATEWAY_INTERFACE=CGI/1.1
SERVER_PROTOCOL=HTTP/1.1
REQUEST_METHOD=GET
QUERY_STRING=
REQUEST_URI=/
SCRIPT_NAME=/wordpress/index.php
PHP_SELF=/wordpress/index.php
REQUEST_TIME=1246683410
argv=Array
argc=0