diff --git a/language/variables.xml b/language/variables.xml
index 7a87ea5e49..6726899337 100644
--- a/language/variables.xml
+++ b/language/variables.xml
@@ -68,7 +68,7 @@ $t
<?php
$foo = 'Bob'; // Assign the value 'Bob' to $foo
-$bar = &$foo; // Reference $foo via $bar.
+$bar = &$foo; // Reference $foo via $bar.
$bar = "My name is $bar"; // Alter $bar...
echo $foo; // $foo is altered too.
echo $bar;
@@ -110,12 +110,14 @@ $bar = &test(); // Invalid.
variables will not be available when PHP is run on the
command-line.
+
Despite these factors, here is a list of predefined variables
available under a stock installation of PHP 3 running as a module
under a stock installation of Apache 1.3.6.
+
For a list of all predefined variables (and lots of other useful
information), please see (and use) phpinfo.
@@ -151,252 +153,252 @@ $bar = &test(); // Invalid.
GATEWAY_INTERFACE
-
- What revision of the CGI specification the server is using;
- i.e. 'CGI/1.1'.
-
+
+ What revision of the CGI specification the server is using;
+ i.e. 'CGI/1.1'.
+ SERVER_NAME
-
- The name of the server host under which the current script is
- executing. If the script is running on a virtual host, this
- will be the value defined for that virtual host.
-
+
+ The name of the server host under which the current script is
+ executing. If the script is running on a virtual host, this
+ will be the value defined for that virtual host.
+ SERVER_SOFTWARE
-
- Server identification string, given in the headers when
- responding to requests.
-
+
+ Server identification string, given in the headers when
+ responding to requests.
+ SERVER_PROTOCOL
-
- Name and revision of the information protocol via which the
- page was requested; i.e. 'HTTP/1.0';
-
+
+ Name and revision of the information protocol via which the
+ page was requested; i.e. 'HTTP/1.0';
+ REQUEST_METHOD
-
- Which request method was used to access the page; i.e. 'GET',
- 'HEAD', 'POST', 'PUT'.
-
+
+ Which request method was used to access the page; i.e. 'GET',
+ 'HEAD', 'POST', 'PUT'.
+ QUERY_STRING
-
- The query string, if any, via which the page was accessed.
-
+
+ The query string, if any, via which the page was accessed.
+ DOCUMENT_ROOT
-
- The document root directory under which the current script is
- executing, as defined in the server's configuration file.
-
+
+ The document root directory under which the current script is
+ executing, as defined in the server's configuration file.
+ HTTP_ACCEPT
-
- Contents of the Accept: header from the
- current request, if there is one.
-
+
+ Contents of the Accept: header from the
+ current request, if there is one.
+ HTTP_ACCEPT_CHARSET
-
- Contents of the Accept-Charset: header
- from the current request, if there is one. Example:
- 'iso-8859-1,*,utf-8'.
-
+
+ Contents of the Accept-Charset: header
+ from the current request, if there is one. Example:
+ 'iso-8859-1,*,utf-8'.
+ HTTP_ENCODING
-
- Contents of the Accept-Encoding: header
- from the current request, if there is one. Example: 'gzip'.
-
+
+ Contents of the Accept-Encoding: header
+ from the current request, if there is one. Example: 'gzip'.
+ HTTP_ACCEPT_LANGUAGE
-
- Contents of the Accept-Language: header
- from the current request, if there is one. Example: 'en'.
-
+
+ Contents of the Accept-Language: header
+ from the current request, if there is one. Example: 'en'.
+ HTTP_CONNECTION
-
- Contents of the Connection: header from
- the current request, if there is one. Example: 'Keep-Alive'.
-
+
+ Contents of the Connection: header from
+ the current request, if there is one. Example: 'Keep-Alive'.
+ HTTP_HOST
-
- Contents of the Host: header from the
- current request, if there is one.
-
+
+ Contents of the Host: header from the
+ current request, if there is one.
+ HTTP_REFERER
-
- The address of the page (if any) which referred the browser
- to the current page. This is set by the user's browser; not
- all browsers will set this.
-
+
+ The address of the page (if any) which referred the browser
+ to the current page. This is set by the user's browser; not
+ all browsers will set this.
+ HTTP_USER_AGENT
-
- Contents of the User_Agent: header from
- the current request, if there is one. This is a string
- denoting the browser software being used to view the current
- page; i.e. Mozilla/4.5 [en] (X11; U; Linux
- 2.2.9 i586). Among other things, you can use
- this value with get_browser to tailor
- your page's functionality to the capabilities of the user's
- browser.
-
+
+ Contents of the User_Agent: header from
+ the current request, if there is one. This is a string
+ denoting the browser software being used to view the current
+ page; i.e. Mozilla/4.5 [en] (X11; U; Linux
+ 2.2.9 i586). Among other things, you can use
+ this value with get_browser to tailor
+ your page's functionality to the capabilities of the user's
+ browser.
+ REMOTE_ADDR
-
- The IP address from which the user is viewing the current
- page.
-
+
+ The IP address from which the user is viewing the current
+ page.
+ REMOTE_PORT
-
- The port being used on the user's machine to communicate with
- the web server.
-
+
+ The port being used on the user's machine to communicate with
+ the web server.
+ SCRIPT_FILENAME
-
- The absolute pathname of the currently executing script.
-
+
+ The absolute pathname of the currently executing script.
+ SERVER_ADMIN
-
- The value given to the SERVER_ADMIN (for Apache) directive in
- the web server configuration file. If the script is running
- on a virtual host, this will be the value defined for that
- virtual host.
-
+
+ The value given to the SERVER_ADMIN (for Apache) directive in
+ the web server configuration file. If the script is running
+ on a virtual host, this will be the value defined for that
+ virtual host.
+ SERVER_PORT
-
- The port on the server machine being used by the web server
- for communication. For default setups, this will be '80';
- using SSL, for instance, will change this to whatever your
- defined secure HTTP port is.
-
+
+ The port on the server machine being used by the web server
+ for communication. For default setups, this will be '80';
+ using SSL, for instance, will change this to whatever your
+ defined secure HTTP port is.
+ SERVER_SIGNATURE
-
- String containing the server version and virtual host name
- which are added to server-generated pages, if enabled.
-
+
+ String containing the server version and virtual host name
+ which are added to server-generated pages, if enabled.
+ PATH_TRANSLATED
-
- Filesystem- (not document root-) based path to the current
- script, after the server has done any virtual-to-real
- mapping.
-
+
+ Filesystem- (not document root-) based path to the current
+ script, after the server has done any virtual-to-real
+ mapping.
+ SCRIPT_NAME
-
- Contains the current script's path. This is useful for pages
- which need to point to themselves.
-
+
+ Contains the current script's path. This is useful for pages
+ which need to point to themselves.
+ REQUEST_URI
-
- The URI which was given in order to access this page; for
- instance, '/index.html'.
-
+
+ The URI which was given in order to access this page; for
+ instance, '/index.html'.
+
@@ -425,140 +427,132 @@ $bar = &test(); // Invalid.
PHP variables
-
+
- These variables are created by PHP itself.
+ These variables are created by PHP itself. The
+ $HTTP_*_VARS variables are available only if
+ the track_vars
+ configuration is turned on.
+
+
+ As of PHP 4.0.3, track_vars is always turned on,
+ regardless of the configuration file setting.
+
+
+
+
+ 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
+ $HTTP_*_VARS arrays. This feature should be
+ used with care, and turned off if possible; while the
+ $HTTP_*_VARS variables are safe, the bare
+ global equivalents can be overwritten by user input, with
+ possibly malicious intent. If you cannot turn off register_globals, you must
+ take whatever steps are necessary to ensure that the data you are
+ using is safe.
+
+
argv
-
- Array of arguments passed to the script. When the script is
- run on the command line, this gives C-style access to the
- command line parameters. When called via the GET method, this
- will contain the query string.
-
+
+ Array of arguments passed to the script. When the script is
+ run on the command line, this gives C-style access to the
+ command line parameters. When called via the GET method, this
+ will contain the query string.
+ argc
-
- Contains the number of command line parameters passed to the
- script (if run on the command line).
-
+
+ Contains the number of command line parameters passed to the
+ script (if run on the command line).
+ PHP_SELF
-
- The filename of the currently executing script, relative to
- the document root. If PHP is running as a command-line
- processor, this variable is not available.
-
+
+ The filename of the currently executing script, relative to
+ the document root. If PHP is running as a command-line
+ processor, this variable is not available.
+ HTTP_COOKIE_VARS
-
- An associative array of variables passed to the current
- script via HTTP cookies. Only available if variable tracking
- has been turned on via either the track_vars configuration
- directive or the
- <?php_track_vars?>
- directive.
-
+
+ An associative array of variables passed to the current
+ script via HTTP cookies.
+ HTTP_GET_VARS
-
- An associative array of variables passed to the current
- script via the HTTP GET method. Only available if variable
- tracking has been turned on via either the track_vars configuration
- directive or the
- <?php_track_vars?>
- directive.
-
+
+ An associative array of variables passed to the current
+ script via the HTTP GET method.
+
-
+
HTTP_POST_VARS
-
- An associative array of variables passed to the current
- script via the HTTP POST method. Only available if variable
- tracking has been turned on via either the track_vars configuration
- directive or the
- <?php_track_vars?>
- directive.
-
+
+ An associative array of variables passed to the current
+ script via the HTTP POST method.
+
-
+ HTTP_POST_FILES
-
- An associative array of variables containing information
- about files uploaded via the HTTP POST method.
- Only available if variable
- tracking has been turned on via either the track_vars configuration
- directive or the
- <?php_track_vars?>
- directive.
-
+
+ An associative array of variables containing information
+ about files uploaded via the HTTP POST method.
+ HTTP_ENV_VARS
-
- An associative array of variables passed to the current
- script via the parent environment. Only available if variable
- tracking has been turned on via either the track_vars configuration
- directive or the
- <?php_track_vars?>
- directive.
-
+
+ An associative array of variables passed to the current
+ script via the parent environment.
+ HTTP_SERVER_VARS
-
- An associative array of variables passed to the current
- script from the HTTP server. These variables are analogous
- to the Apache variables described above.
- Only available if variable
- tracking has been turned on via either the track_vars configuration
- directive or the
- <?php_track_vars?>
- directive.
-
+
+ An associative array of variables passed to the current
+ script from the HTTP server. These variables are analogous to
+ the Apache variables described above.
+
-
-
@@ -583,11 +577,11 @@ include "b.inc";
- Here the $a variable will be available within the included b.inc
- script. However, within user-defined functions a local function
- scope is introduced. Any variable used inside a function is by
- default limited to the local function scope. For
- example:
+ Here the $a variable will be available within
+ the included b.inc script. However, within
+ user-defined functions a local function scope is introduced. Any
+ variable used inside a function is by default limited to the local
+ function scope. For example:
@@ -604,14 +598,16 @@ Test ();
This script will not produce any output because the echo statement
- refers to a local version of the $a variable, and it has not been
- assigned a value within this scope. You may notice that this is a
- little bit different from the C language in that global variables
- in C are automatically available to functions unless specifically
- overridden by a local definition. This can cause some problems in
- that people may inadvertently change a global variable. In PHP
- global variables must be declared global inside a function if they
- are going to be used in that function. An example:
+ refers to a local version of the $a variable,
+ and it has not been assigned a value within this scope. You may
+ notice that this is a little bit different from the C language in
+ that global variables in C are automatically available to
+ functions unless specifically overridden by a local definition.
+ This can cause some problems in that people may inadvertently
+ change a global variable. In PHP global variables must be
+ declared global inside a function if they are going to be used in
+ that function. An example:
+
@@ -630,17 +626,17 @@ echo $b;
- The above script will output "3". By declaring $a and
- $b global within the function, all references to either variable
- will refer to the global version. There is no limit to the number
- of global variables that can be manipulated by a
- function.
+ The above script will output "3". By declaring
+ $a and $b global within the
+ function, all references to either variable will refer to the
+ global version. There is no limit to the number of global
+ variables that can be manipulated by a function.
A second way to access variables from the global scope is to use
- the special PHP-defined $GLOBALS array. The previous example can
- be rewritten as:
+ the special PHP-defined $GLOBALS array. The
+ previous example can be rewritten as:
@@ -658,9 +654,9 @@ echo $b;
- The $GLOBALS array is an associative array with the name of the
- global variable being the key and the contents of that variable
- being the value of the array element.
+ The $GLOBALS array is an associative array with
+ the name of the global variable being the key and the contents of
+ that variable being the value of the array element.
@@ -683,11 +679,13 @@ Function Test () {
This function is quite useless since every time it is called it
- sets $a to 0 and prints "0". The $a++ which increments
- the variable serves no purpose since as soon as the function exits
- the $a variable disappears. To make a useful counting function
- which will not lose track of the current count, the $a variable is
- declared static:
+ sets $a to 0 and prints
+ "0". The $a++ which increments the
+ variable serves no purpose since as soon as the function exits the
+ $a variable disappears. To make a useful
+ counting function which will not lose track of the current count,
+ the $a variable is declared static:
+
@@ -701,7 +699,7 @@ Function Test () {
Now, every time the Test() function is called it will print the
- value of $a and increment it.
+ value of $a and increment it.
@@ -711,7 +709,7 @@ Function Test () {
possible to make it recurse indefinitely. You must make sure you
have an adequate way of terminating the recursion. The following
simple function recursively counts to 10, using the static
- variable $count to know when to stop:
+ variable $count to know when to stop:
@@ -761,8 +759,9 @@ $$a = "world";
At this point two variables have been defined and stored in the
- PHP symbol tree: $a with contents "hello" and $hello with contents
- "world". Therefore, this statement:
+ PHP symbol tree: $a with contents "hello" and
+ $hello with contents "world". Therefore, this
+ statement:
@@ -782,17 +781,18 @@ echo "$a $hello";
- i.e. they both produce: hello world.
+ i.e. they both produce: hello world.
In order to use variable variables with arrays, you have to
- resolve an ambiguity problem. That is, if you write $$a[1] then
- the parser needs to know if you meant to use $a[1] as a variable,
- or if you wanted $$a as the variable and then the [1] index from
- that variable. The syntax for resolving this ambiguity is:
- ${$a[1]} for the first case and ${$a}[1] for the
- second.
+ resolve an ambiguity problem. That is, if you write
+ $$a[1] then the parser needs to know if you
+ meant to use $a[1] as a variable, or if you
+ wanted $$a as the variable and then the [1]
+ index from that variable. The syntax for resolving this ambiguity
+ is: ${$a[1]} for the first case and
+ ${$a}[1] for the second.
@@ -806,33 +806,48 @@ echo "$a $hello";
When a form is submitted to a PHP script, any variables from that
form will be automatically made available to the script by
- PHP. For instance, consider the following form:
+ PHP. If the track_vars
+ configuration option is turned on, then these variables will be
+ located in the associative arrays
+ $HTTP_POST_VARS,
+ $HTTP_GET_VARS, and/or
+ $HTTP_POST_FILES, according to the
+ source of the variable in question.
+
+ For more information on these variables, please read Predefined
+ variables.
+
+
Simple form variable
-<form action="foo.php3" method="post">
- Name: <input type="text" name="name"><br>
+<form action="foo.php" method="post">
+ Name: <input type="text" name="username"><br>
<input type="submit">
</form>
-
- When submitted, PHP will create the variable
- $name, which will will contain
- whatever what entered into the Name: field
- on the form.
-
+
+ When the above form is submitted, the value from the text input
+ will be available in
+ $HTTP_POST_VARS['username']. If the register_globals
+ configuration directive is turned on, then the variable will also
+ be available as $username in the global scope.
+
- PHP also understands arrays in the context of form variables, but
- only in one dimension. You may, for example, group related
- variables together, or use this feature to retrieve values from a
- multiple select input:
+ PHP also understands arrays in the context of form variables. You
+ may, for example, group related variables together, or use this
+ feature to retrieve values from a multiple select
+ input:
+
@@ -853,14 +868,10 @@ echo "$a $hello";
-
- If PHP's track_vars feature is turned on, either by the track_vars configuration setting
- or the <?php_track_vars?>
- directive, then variables submitted via the POST or GET methods
- will also be found in the global associative arrays
- $HTTP_POST_VARS and $HTTP_GET_VARS as appropriate.
-
+
+ In PHP 3, the array form variable usage is limited to
+ single-dimensional arrays. In PHP 4, no such restriction applies.
+ IMAGE SUBMIT variable names
@@ -969,11 +980,11 @@ echo $HOME; /* Shows the HOME environment variable, if set. */
$varname.ext; /* invalid variable name */
- Now, what the parser sees is a variable named $varname, followed
- by the string concatenation operator, followed by the barestring
- (i.e. unquoted string which doesn't match any known key or
- reserved words) 'ext'. Obviously, this doesn't have the intended
- result.
+ Now, what the parser sees is a variable named
+ $varname, followed by the string concatenation
+ operator, followed by the barestring (i.e. unquoted string which
+ doesn't match any known key or reserved words) 'ext'. Obviously,
+ this doesn't have the intended result.