Pre-Defined Server 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_Country_Code

GB

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

Geoip_City_Country_Code3

GBR

This is the 3 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

[empty]

This is typically undefined, unless you subscribe to a GeoIP city database.

Geoip_City

[empty]

This is typically undefined, unless you subscribe to a GeoIP city database.

Geoip_Postal_Code

[empty]

This is typically undefined, unless you subscribe to a GeoIP city database.

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.