Is my understand regarding superglobal arrays $_ENV and $_SERVER correct ?
$_ENV: Contains information about environment variables
$_SERVER: Contains information about the server$_ENV is accessible from both web server and on the command line
$_SERVER is accessible through only web server, not on the command line
$_ENV is another superglobal associative array in PHP. It stores environment variables available to current script. $HTTP_ENV_VARS also contains the same information, but is not a superglobal, and now been deprecated. Environment variables are imported into global namespace.
$_SERVER is a PHP super global variable which holds information about headers, paths, and script locations.
$_SERVER['PHP_SELF'] Contains the file name of the currently running script. $_SERVER['GATEWAY_INTERFACE'] Contains the version of the Common Gateway Interface being used by the server.
$_SERVER['SCRIPT_NAME'] is server-side. There are no browser compatibility issues as a result, and there shouldn't be security issues as it simply an indication of what the server is serving for the requested URL (i.e. http://example.com/ and http://example.com/index.php would both result in '/index. php' ).
Put this code in a file:
<?php
header('Content-Type: text/plain');
echo('$_ENV[] = '); print_r($_ENV);
echo('$_SERVER[] = '); print_r($_SERVER);
Run it using the command line and the web server and see what you get.
To my surprise, on my computer $_ENV[]
is empty on both setups and $_SERVER[]
contains the environment variables when the code runs from the CLI.
In general, the outcome depends a lot on the operating system and web server you use.
You are half right :)
$_ENV contains information about the environment which the PHP interpreter is running in.
Both $_ENV and $_SERVER are accessible from command line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With