![]() | Variabili predefiniteA partire dal PHP 4.1.0, il metodo raccomandato per ottenere le variabili esterne è quello di usare i superglobals, come spiegato più sotto. In precedenza, gli sviluppatori si appoggiavano ai register_globals o agli array predefiniti ($HTTP_*_VARS). As of PHP 5.0.0, the long PHP predefined variable arrays may be disabled with the register_long_arrays directive. Variabili di server: $_SERVER
$_SERVER è un array che contiene informazioni quali header, percorsi e posizioni degli script. Le voci in questo array sono create dal server web. non c'è garanzia che ogni server web fornisca queste informazioni; i server possono ometterne alcune, oppure fornirne altre non contemplate qui. Detto questo, gran parte di queste variabili sono contemplate nelle specifiche CGI 1.1, quindi è molto probabile ritrovarle in questo array. Questo array è una variabile 'superglobal', o globale automatica. Ciò siginifica che è disponibile in tutti gli scope all'interno di uno script. Non è necessario scrivere global $_SERVER; per accedervi in una funzione o metodo, come invece occorreva fare con $HTTP_SERVER_VARS. $HTTP_SERVER_VARS contiene le stesse informazioni, ma non è autoglobal. (si noti che $HTTP_SERVER_VARS e $_SERVER sono variabili distinte e che PHP le tratta di conseguenza) Se la direttiva register_globals è impostata, queste informazioni saranno rese disponibili anche nello scope globale dello script; quindi in variabili diverse da $_SERVER e $HTTP_SERVER_VARS arrays. Per la documentazione correlata, vedere il capitolo sulla sicurezza intitolato Utilizzo dei Register Globals. Queste variabili globali individuali non sono autoglobal. You may or may not find any of the following elements in $_SERVER. Note that few, if any, of these will be available (or indeed have any meaning) if running PHP on the command line.
Environment variables: $_ENV
These variables are imported into PHP's global namespace from the environment under which the PHP parser is running. Many are provided by the shell under which PHP is running and different systems are likely running different kinds of shells, a definitive list is impossible. Please see your shell's documentation for a list of defined environment variables. Other environment variables include the CGI variables, placed there regardless of whether PHP is running as a server module or CGI processor. This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_ENV; to access it within functions or methods, as you do with $HTTP_ENV_VARS. $HTTP_ENV_VARS contains the same initial information, but is not an autoglobal. (Note that $HTTP_ENV_VARS and $_ENV are different variables and that PHP handles them as such) If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_ENV and $HTTP_ENV_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals. HTTP Cookies: $_COOKIE
An associative array of variables passed to the current script via HTTP cookies. Automatically global in any scope. This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_COOKIE; to access it within functions or methods, as you do with $HTTP_COOKIE_VARS. $HTTP_COOKIE_VARS contains the same initial information, but is not an autoglobal. (Note that $HTTP_COOKIE_VARS and $_COOKIE are different variables and that PHP handles them as such) If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_COOKIE and $HTTP_COOKIE_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals. HTTP GET variables: $_GET
An associative array of variables passed to the current script via the HTTP GET method. Automatically global in any scope. This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_GET; to access it within functions or methods, as you do with $HTTP_GET_VARS. $HTTP_GET_VARS contains the same initial information, but is not an autoglobal. (Note that $HTTP_GET_VARS and $_GET are different variables and that PHP handles them as such) If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_GET and $HTTP_GET_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals. HTTP POST variables: $_POST
An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope. This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_POST; to access it within functions or methods, as you do with $HTTP_POST_VARS. $HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that $HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such) If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_POST and $HTTP_POST_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals. HTTP File upload variables: $_FILES
An associative array of items uploaded to the current script via the HTTP POST method. Automatically global in any scope. This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_FILES; to access it within functions or methods, as you do with $HTTP_POST_FILES. $HTTP_POST_FILES contains the same information, but is not an autoglobal. (Note that $HTTP_POST_FILES and $_FILES are different variables and that PHP handles them as such) If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_FILES and $HTTP_POST_FILES arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals. Request variables: $_REQUEST
An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE. This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_REQUEST; to access it within functions or methods. If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_REQUEST array. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals. Session variables: $_SESSION
An associative array containing session variables available to the current script. See the Session functions documentation for more information on how this is used. This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_SESSION; to access it within functions or methods, as you do with $HTTP_SESSION_VARS. $HTTP_SESSION_VARS contains the same information, but is not an autoglobal. (Note that $HTTP_SESSION_VARS and $_SESSION are different variables and that PHP handles them as such) If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_SESSION and $HTTP_SESSION_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals. Global variables: $GLOBALS
An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array. This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $GLOBALS; to access it within functions or methods. The previous error message: $php_errormsg$php_errormsg is a variable containing the text of the last error message generated by PHP. This variable will only be available within the scope in which the error occurred, and only if the track_errors configuration option is turned on (it defaults to off). | ![]() |