Pre-Defined Server Variables

Table of Contents

  1. Variables

MageStack has a number of predefined server variables ($_SERVER) that you can utilise for adding additional functionality, debugging or logging. A key benefit is that we accelerate some functionality in the OS itself, such as GeoIP lookups; which means the overhead of PHP classes or the PHP Extension for GeoIP isn't required for gathering simple information.

Variables

Eg. For the request www.example.com/?foo=bar

USER

www-data

This defines the user (or domain group) the process is running as.

HOME

/var/www

This merely defines the home directory of the user, this information is not used/relevant.

SCRIPT_FILENAME

/domains/example.com/www/index.php

This is the name of the PHP file currently being executed. With Magento, in 99% of cases this will be the bootstrap (index.php).

MAGE_RUN_CODE

[empty]

This is the environment variable for the Magento run code, by default it is empty, it is defined at the vhost level. See this article for more information on setting this variable.

MAGE_RUN_TYPE

[empty]

This is the environment variable for the Magento run type, by default it is empty, it is defined at the vhost level. See this article for more information on setting this variable.

QUERY_STRING

foo=bar

This is the query string provided in the URI (eg. everything after ?).

REQUEST_METHOD

GET|POST|...

This is the HTTP request method used.

CONTENT_TYPE

[empty]

This is typically undefined.

CONTENT_LENGTH

[empty]

This is typically undefined, unless there are file uploads within the request.

SCRIPT_NAME

/index.php

This is the name of the script being executed, relative to the document root.

REQUEST_URI

/?foo=bar

This is the part of the URL following the domain, including the query string.

DOCUMENT_URI

/index.php

This is the name of the script being executed, relative to the document root.

DOCUMENT_ROOT

/domains/example.com/www

This is the directory the request is being served from, relative to its domain group.

SERVER_PROTOCOL

HTTP/1.1

This is the version of the HTTP protocol being used for the request.

GATEWAY_INTERFACE

CGI/1.1

This is the version of CGI being used for the request.

SERVER_SOFTWARE

nginx/1.6.0

This is the version and type of web server software in use.

REMOTE_PORT

[empty]

This is typically undefined

SERVER_ADDR

172.16.0.71

This is the internal IP address of the web server (see full list of internal IP addresses).

SERVER_PORT

80|81

Port 80 is used for HTTP/HTTPS requests. Port 81 is used for SPDY requests.

SERVER_NAME

example.com

This is the name of the vhost (not the full URL as seen in the browser).

REDIRECT_STATUS

200

This is the HTTP response header set by the CGI process.

REMOTE_ADDR

x.x.x.x

This is the IP address of the user/server making the request. Regardless of what load balancer, MSE node or web node this has been processed through, this will always reflect the true IP of the visitor.

HTTPS

on|off

If the request is a HTTP request, this is defined as off; if the request is HTTPS, this is defined as on.

HTTP_X_FORWARDED_PROTOCOL

http

If the request is a HTTP request, this is defined as http; if the request is HTTPS, this is defined as https.

GEOIP_ASN

199542

This is the autonomous system number of the user/server making the request.

GEOIP_COUNTRY_CODE

GB

This is the 2 digit ISO country code representing the location of the user/server making the request.

GEOIP_COUNTRY_NAME

United Kingdom

This is the country name representing the location of the user/server making the request.

GEOIP_REGION

ENG

This is the name representing the region of the user/server making the request (if available).

GEOIP_CITY

Manchester

This is the city name representing the location of the user/server making the request.

GEOIP_POSTAL_CODE

M1

This is the postal code representing the location of the user/server making the request (if available).

GEOIP_CITY_CONTINENT_CODE

EU

This is the 2 digit ISO country code representing the continent of the user/server making the request.

GEOIP_LATITUDE

51.5000

This is the latitude representing the location of the user/server making the request.

GEOIP_LONGITUDE

-0.1300

This is the longitude representing the location of the user/server making the request.

HTTP_HOST

www.example.com

This is the full URL as seen in the browser.

HTTP_USER_AGENT

Mozilla/5.0 (Windows NT 5.2; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0

This is the user agent of the user/server making the request.

HTTP_ACCEPT

text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

This is the the types of data of the user/server making the request can accept.

HTTP_ACCEPT_LANGUAGE

en

This is the the language of the user/server making the request.

HTTP_COOKIE

...

This is the cookie sent by the user/server making the request.

HTTP_MAGESTACK_LOADBALANCER

x.x.x.x

This is the public IP of the MageStack loadbalancer, or MageStack Edge node that accepted the original request.

HTTP_MAGESTACK_DOS_STATS

dos-active

This variable is only set when the DOS filter is enabled. This is enabled by default, unless specifically disabled.

HTTP_MAGESTACK_AREA

Frontend|Admin|PaymentBridge

This the the defined area set by the load balancer for the request (read more about request headers)

HTTP_MAGESTACK_TAG

Dynamic|Static

This is the tag attached by the load balancer as it tries to identify the type of request before any processing actually takes place. This is used for the DOS filter.

HTTP_MAGESTACK_WHITELISTED_HTTP_HOST

true

This variable is only set if the if the HTTP host for the request has been whitelisted on the DOS filter.

HTTP_MAGESTACK_WHITELISTED_IP

true

This variable is only set if the if the source IP address of the request (the client/server) has been whitelisted on the DOS filter.

HTTP_MAGESTACK_WHITELISTED_URI

true

This variable is only set if the if the requested URI has been whitelisted on the DOS filter.

HTTP_MAGESTACK_WHITELISTED_USERAGENT

true

This variable is only set if the user agent of the request (the client/server) has been whitelisted on the DOS filter.

HTTP_X_FORWARDED_FOR

x.x.x.x

This variable is used for the server itself to track the client/server REMOTE_ADDR effectively. It should not be used for purposes other than debugging request path/channels.

HTTP_VARNISH_ENABLED

0|1

This is set to 1 by default. It does not mean the current page is cached in Varnish, nor that Varnish is enabled for this URL/vhost/domain. It specifically refers to Varnish being enabled in the load balancer.

HTTP_SEPARATE_SCHEME

0|1

This is set to 1 by default. It means that Varnish maintains a separate cache for a request with the same URI for each scheme (HTTP/HTTPS), so that HTTPS assets are not utilised on HTTP pages (and vice-versa). This does impact hit rates, but avoids the much larger issue of browsers blocking mixed content.

HTTP_ACCEPT_ENCODING

gzip|...

This defines the type of encoding accepted by the client/server.

HTTP_CONNECTION

close|chunked|...

This is set to closed by default.

PHP_SELF

/index.php

This is the name of the script being executed, relative to the document root.

REQUEST_TIME

1405678165

This is the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) for when the request started.

MY_MAGE_MODE

[empty]

This variable is used to determine Magento's application mode. For stores using Magento 2, this variable will be set to default by default. It can be set to any string value, but should typically be set to production or developer for live or staging sites respectively.

This variable's value will override any value set in Magento's own configuration file.

To update this value, visit the following article.