All articles

Configure PHP and connected services

Set PHP variables_order to Populate the Superglobals You Need

Choose a PHP variables_order value, verify GET, POST, COOKIE and ENV inputs, and check request_order separately for $_REQUEST.

Editorial illustration for Set PHP variables_order to Populate the Superglobals You Need

If $_ENV, $_GET, $_POST, or $_COOKIE is missing data you expected, check the active variables_order value before changing application code. Its letters select which superglobal arrays PHP populates. EGPCS includes $_ENV; GPCS leaves E out while retaining the GET, POST, COOKIE, and SERVER arrays. Neither value tells the whole story for $_REQUEST, so check request_order separately when your code reads it.

Choose the letters your application needs

The mapping is short, but one letter is easy to misread:

Letter Superglobal Data source
E $_ENV Environment variables
G $_GET Query-string parameters
P $_POST POST form data
C $_COOKIE Cookies
S $_SERVER Server variables

S means $_SERVER, not $_SESSION. The letters in this directive do not include a session setting. The PHP.Watch directive reference identifies these five abbreviations and describes variables_order as determining which superglobal arrays are registered when PHP starts.

Read EGPCS as a choice to populate all five listed arrays. Read GPCS as the same choice without E. If application code reads $_ENV, that difference matters; if it does not, including E may be unnecessary. The source lists EGPCS as a default, but another configuration reference cautions that defaults can vary with PHP version and server setup. Treat a stated default as a clue, not as the value running in your application.

Set and verify the directive

Identify the php.ini used by the PHP runtime serving the application, then locate its variables_order = line. For an application that needs all five arrays, the setting is:

variables_order = "EGPCS"

If it does not need $_ENV, the alternative is:

variables_order = "GPCS"

Compare the configured line with what that same runtime reports. A value found in a different PHP configuration does not establish what the application is using. To check both directives and inspect a request, place this diagnostic where it runs in the application’s PHP context. It is an example, not a report of an executed test:

<?php

echo 'variables_order: ', ini_get('variables_order'), "\n";
echo 'request_order: ', ini_get('request_order'), "\n";

echo 'GET: '; var_dump($_GET['probe_get'] ?? null);
echo 'POST: '; var_dump($_POST['probe_post'] ?? null);
echo 'COOKIE: '; var_dump($_COOKIE['probe_cookie'] ?? null);

echo 'ENV array: '; var_dump($_ENV['PHP_PROBE_ENV'] ?? null);
echo 'getenv: '; var_dump(getenv('PHP_PROBE_ENV'));
echo 'SERVER environment check: '; var_dump($_SERVER['PHP_PROBE_ENV'] ?? null);

echo 'REQUEST GET key: '; var_dump($_REQUEST['probe_get'] ?? null);
echo 'REQUEST POST key: '; var_dump($_REQUEST['probe_post'] ?? null);
echo 'REQUEST COOKIE key: '; var_dump($_REQUEST['probe_cookie'] ?? null);

Supply distinct, known values for probe_get in the query string, probe_post in a POST request, and probe_cookie in a cookie sent with that request. Check each value in its corresponding array. Run the environment comparison only after making a known PHP_PROBE_ENV value available to the PHP process; otherwise, a missing value does not tell you whether E was selected. The null fallback in the array checks makes an absent test key visible, but it cannot by itself explain why the key is absent.

The first two lines give you the values to compare with your intended configuration. The input checks then test the consequence that matters to your application. Do not treat a matching variables_order string as proof that a particular GET, POST, or COOKIE value was actually sent in the request.

Check $_REQUEST separately

If code reads $_REQUEST, inspect its results rather than inferring them from variables_order. The supplied guide to $_REQUEST says that request_order controls the order in which GET, POST, and COOKIE variables are registered there. Compare the diagnostic’s request_order value and observed $_REQUEST keys with the inputs you supplied. In particular, a value present in $_COOKIE does not, on its own, establish that the application will find it in $_REQUEST.

When the expected source is known, read $_GET, $_POST, or $_COOKIE directly. That makes the intended source explicit instead of accepting a value collected from multiple possible input sources through $_REQUEST.

Decide whether to include E

PHP.Watch advises against including ENV on production servers when it is not needed and notes that getenv() remains an alternative for accessing environment variables. That gives you a practical reason to choose GPCS if the application does not read $_ENV; choose EGPCS when populating $_ENV is part of its intended configuration.

Keep the environment checks distinct. The diagnostic compares $_ENV['PHP_PROBE_ENV'] with getenv('PHP_PROBE_ENV') so access through the function is not mistaken for population of the array. A reported CGI and FastCGI behavior is that environment values are also stored in $_SERVER under those SAPIs. The $_SERVER check can help interpret results in that setting, but it is not a substitute for checking $_ENV when your code specifically uses $_ENV.

The useful endpoint is an observed match: the active directive has the intended letters, known request values appear in their expected input arrays, and any $_REQUEST result is assessed against request_order rather than an assumed variables_order default.

← All articles