http://us2.php.net/reserved.variables



<?php echo($_SERVER['PHP_SELF']) ?>


Predefined Variables

Since PHP 4.1.0, the preferred method for retrieving external variables is with the superglobals mentioned below. Before this time, people relied on either register_globals or the long predefined PHP arrays ($HTTP_*_VARS). As of PHP 5.0.0, the long PHP predefined variable arrays may be disabled with the register_long_arrays directive.

Server variables: $_SERVER

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the webserver. There is no guarantee that every webserver will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the CGI 1.1 specification, so you should be able to expect those.

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 $_SERVER; to access it within functions or methods, as you do with $HTTP_SERVER_VARS.

$HTTP_SERVER_VARS contains the same initial information, but is not an autoglobal. (Note that $HTTP_SERVER_VARS and $_SERVER 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 $_SERVER and $HTTP_SERVER_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.

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.



'PHP_SELF'

/php/server_vars/resvars.php

The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar.

If PHP is running as a command-line processor, this variable is not available.

'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.

'argc'

Contains the number of command line parameters passed to the script (if run on the command line).

'GATEWAY_INTERFACE'

CGI/1.1

What revision of the CGI specification the server is using; i.e. 'CGI/1.1'.

'SERVER_NAME'

www.santiago.bz

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'

Apache

Server identification string, given in the headers when responding to requests.

'SERVER_PROTOCOL'

HTTP/2.0

Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0';

'REQUEST_METHOD'

GET

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.

'DOCUMENT_ROOT'

/home/echeverry/santiago.bz

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.

'HTTP_ACCEPT_CHARSET'



Contents of the Accept-Charset: header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'.

'HTTP_ACCEPT_ENCODING'



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'.

'HTTP_CONNECTION'

close

Contents of the Connection: header from the current request, if there is one. Example: 'Keep-Alive'.

'HTTP_HOST'

www.santiago.bz

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 user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

'HTTP_USER_AGENT'

claudebot

Contents of the User-Agent: header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page. A typical example is: 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 output to the capabilities of the user agent.

'REMOTE_ADDR'

3.80.173.25

The IP address from which the user is viewing the current page.

'REMOTE_HOST'



The Host name from which the user is viewing the current page. The reverse dns lookup is based off the REMOTE_ADDR of the user.

Note: Your web server must be configured to create this variable. For example in Apache you'll need HostnameLookups On inside httpd.conf for it to exist. See also gethostbyaddr().

'REMOTE_PORT'

47004

The port being used on the user's machine to communicate with the web server.

'SCRIPT_FILENAME'

/home/echeverry/santiago.bz/php/server_vars/resvars.php

The absolute pathname of the currently executing script.

Note: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php, $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.


'SERVER_ADMIN'

webmaster@santiago.bz

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'

443

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.

'PATH_TRANSLATED'



Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.

'SCRIPT_NAME'

/php/server_vars/resvars.php

Contains the current script's path. This is useful for pages which need to point to themselves.

'REQUEST_URI'

/php/server_vars/resvars.php

The URI which was given in order to access this page; for instance, '/index.html'.

'PHP_AUTH_USER'



When running under Apache as module doing HTTP authentication this variable is set to the username provided by the user.

'PHP_AUTH_PW'



When running under Apache as module doing HTTP authentication this variable is set to the password provided by the user.

'AUTH_TYPE'



When running under Apache as module doing HTTP authenticated this variable is set to the authentication type.