Source of: /manual/en/reserved.variables.server.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/reserved.variables.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'reserved.variables.server.php',
1 => '$_SERVER',
),
'up' =>
array (
0 => 'reserved.variables.php',
1 => 'Predefined Variables',
),
'prev' =>
array (
0 => 'reserved.variables.globals.php',
1 => '$GLOBALS',
),
'next' =>
array (
0 => 'reserved.variables.get.php',
1 => '$_GET',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="reserved.variables.server" class="refentry">
<div class="refnamediv">
<h1 class="refname">$_SERVER</h1>
<h1 class="refname">$HTTP_SERVER_VARS [deprecated]</h1>
<p class="refpurpose"><span class="refname">$_SERVER</span> -- <span class="refname">$HTTP_SERVER_VARS [deprecated]</span> — <span class="dc-title">Server and execution environment information</span></p>
</div>
<a name="reserved.variables.server.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<p class="para">
<var class="varname">$_SERVER</var> is an array containing information
such as headers, paths, and script locations. The entries in this
array are created by the web server. There is no guarantee that
every web server 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 <a href="http://hoohoo.ncsa.uiuc.edu/cgi/env.html" class="link external">» CGI 1.1 specification</a>, so you should
be able to expect those.
</p>
<p class="simpara">
<var class="varname">$HTTP_SERVER_VARS</var> contains the same initial
information, but is not a <a href="language.variables.superglobals.php" class="link">superglobal</a>.
(Note that <var class="varname">$HTTP_SERVER_VARS</var> and <var class="varname">$_SERVER</var>
are different variables and that PHP handles them as such)
</p>
</div>
<a name="reserved.variables.server.indices"></a><div class="refsect1 indices">
<h3 class="title">Indices</h3>
<p class="simpara">
You may or may not find any of the following elements in
<var class="varname">$_SERVER</var>. Note that few, if any, of these will be
available (or indeed have any meaning) if running PHP on the
<a href="features.commandline.php" class="link">command line</a>.
</p>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term">'<var class="varname">PHP_SELF</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
The filename of the currently executing script, relative to
the document root. For instance,
<var class="varname">$_SERVER['PHP_SELF']</var> in a script at the
address <var class="filename">http://example.com/test.php/foo.bar</var>
would be <var class="filename">/test.php/foo.bar</var>.
The <a href="language.constants.predefined.php" class="link">__FILE__</a>
constant contains the full path and filename of the current (i.e.
included) file.
</span>
<span class="simpara">
If PHP is running as a command-line processor this variable contains
the script name since PHP 4.3.0. Previously it was not available.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<a href="reserved.variables.argv.php" class="link">argv</a>'</span>
</dt><dd class="listitem">
<span class="simpara">
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.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<a href="reserved.variables.argc.php" class="link">argc</a>'</span>
</dt><dd class="listitem">
<span class="simpara">
Contains the number of command line parameters passed to the
script (if run on the command line).
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">GATEWAY_INTERFACE</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
What revision of the CGI specification the server is using;
i.e. '<i>CGI/1.1</i>'.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">SERVER_ADDR</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
The IP address of the server under which the current script is
executing.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">SERVER_NAME</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
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.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">SERVER_SOFTWARE</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Server identification string, given in the headers when
responding to requests.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">SERVER_PROTOCOL</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Name and revision of the information protocol via which the
page was requested; i.e. '<i>HTTP/1.0</i>';
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">REQUEST_METHOD</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Which request method was used to access the page; i.e. '<i>GET</i>',
'<i>HEAD</i>', '<i>POST</i>', '<i>PUT</i>'.
</span>
<blockquote><p><b class="note">Note</b>:
PHP script is terminated after sending headers (it means after
producing any output without output buffering) if the request method
was <i>HEAD</i>.
<br />
</p></blockquote>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">REQUEST_TIME</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
The timestamp of the start of the request. Available since PHP 5.1.0.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">QUERY_STRING</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
The query string, if any, via which the page was accessed.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">DOCUMENT_ROOT</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
The document root directory under which the current script is
executing, as defined in the server's configuration file.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">HTTP_ACCEPT</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Contents of the <i>Accept:</i> header from the
current request, if there is one.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">HTTP_ACCEPT_CHARSET</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Contents of the <i>Accept-Charset:</i> header
from the current request, if there is one. Example:
'<i>iso-8859-1,*,utf-8</i>'.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">HTTP_ACCEPT_ENCODING</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Contents of the <i>Accept-Encoding:</i> header
from the current request, if there is one. Example: '<i>gzip</i>'.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">HTTP_ACCEPT_LANGUAGE</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Contents of the <i>Accept-Language:</i> header
from the current request, if there is one. Example: '<i>en</i>'.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">HTTP_CONNECTION</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Contents of the <i>Connection:</i> header from
the current request, if there is one. Example: '<i>Keep-Alive</i>'.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">HTTP_HOST</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Contents of the <i>Host:</i> header from the
current request, if there is one.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">HTTP_REFERER</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
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 <var class="varname">HTTP_REFERER</var> as a feature. In
short, it cannot really be trusted.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">HTTP_USER_AGENT</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Contents of the <i>User-Agent:</i> 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: <span class="computeroutput">Mozilla/4.5 [en] (X11; U;
Linux 2.2.9 i586)</span>. Among other things, you
can use this value with <a href="function.get-browser.php" class="function">get_browser()</a> to
tailor your page's output to the capabilities of the user
agent.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">HTTPS</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Set to a non-empty value if the script was queried through the HTTPS
protocol.
</span>
<blockquote><p><b class="note">Note</b>:
<span class="simpara">
Note that when using ISAPI with IIS, the value will be
<i>off</i> if the request was not made through the HTTPS
protocol.
</span>
</p></blockquote>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">REMOTE_ADDR</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
The IP address from which the user is viewing the current
page.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">REMOTE_HOST</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
The Host name from which the user is viewing the current
page. The reverse dns lookup is based off the
<var class="varname">REMOTE_ADDR</var> of the user.
</span>
<blockquote><p><b class="note">Note</b>:
<span class="simpara">
Your web server must be configured to create this variable. For
example in Apache you'll need <i>HostnameLookups On</i>
inside <var class="filename">httpd.conf</var> for it to exist. See also
<a href="function.gethostbyaddr.php" class="function">gethostbyaddr()</a>.
</span>
</p></blockquote>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">REMOTE_PORT</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
The port being used on the user's machine to communicate with
the web server.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">SCRIPT_FILENAME</var>'</span>
</dt><dd class="listitem">
<p class="para">
The absolute pathname of the currently executing script.
</p><blockquote><p><b class="note">Note</b>:
If a script is executed with the CLI, as a relative path,
such as <var class="filename">file.php</var> or
<var class="filename">../file.php</var>,
<var class="varname">$_SERVER['SCRIPT_FILENAME']</var> will
contain the relative path specified by the user.
<br />
</p></blockquote><p>
</p>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">SERVER_ADMIN</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
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.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">SERVER_PORT</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
The port on the server machine being used by the web server
for communication. For default setups, this will be '<i>80</i>';
using SSL, for instance, will change this to whatever your
defined secure HTTP port is.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">SERVER_SIGNATURE</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
String containing the server version and virtual host name
which are added to server-generated pages, if enabled.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">PATH_TRANSLATED</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Filesystem- (not document root-) based path to the current
script, after the server has done any virtual-to-real
mapping.
</span>
<blockquote><p><b class="note">Note</b>:
<span class="simpara">
As of PHP 4.3.2, <span class="envar">PATH_TRANSLATED</span> is no longer set
implicitly under the Apache 2 <acronym title="Server Application Programming Interface">SAPI</acronym> in contrast
to the situation in Apache 1, where it's set to the same value as
the <span class="envar">SCRIPT_FILENAME</span> server variable when it's not
populated by Apache. This change was made to comply with the
<acronym title="Common Gateway Interface">CGI</acronym> specification that
<span class="envar">PATH_TRANSLATED</span> should only exist if
<span class="envar">PATH_INFO</span> is defined.
</span>
<span class="simpara">
Apache 2 users may use <i>AcceptPathInfo = On</i> inside
<var class="filename">httpd.conf</var> to define <span class="envar">PATH_INFO</span>.
</span>
</p></blockquote>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">SCRIPT_NAME</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Contains the current script's path. This is useful for pages
which need to point to themselves.
The <a href="language.constants.predefined.php" class="link">__FILE__</a>
constant contains the full path and filename of the current (i.e.
included) file.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">REQUEST_URI</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
The URI which was given in order to access this page; for
instance, '<i>/index.html</i>'.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">PHP_AUTH_DIGEST</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
When running under Apache as module doing Digest HTTP authentication
this variable is set to the 'Authorization' header sent by the
client (which you should then use to make the appropriate
validation).
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">PHP_AUTH_USER</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
When running under Apache or IIS (ISAPI on PHP 5) as module doing
HTTP authentication this variable is set to the username provided by
the user.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">PHP_AUTH_PW</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
When running under Apache or IIS (ISAPI on PHP 5) as module doing
HTTP authentication this variable is set to the password provided by
the user.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">AUTH_TYPE</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
When running under Apache as module doing HTTP authenticated this
variable is set to the authentication type.
</span>
</dd>
<dt class="varlistentry">
<span class="term">'<var class="varname">PATH_INFO</var>'</span>
</dt><dd class="listitem">
<span class="simpara">
Contains any client-provided pathname information trailing the
actual script filename but preceding the query string, if
available. For instance, if the current script was accessed via
the
URL <var class="filename">http://www.example.com/php/path_info.php/some/stuff?foo=bar</var>,
then <var class="varname">$_SERVER['PATH_INFO']</var> would
contain <i>/some/stuff</i>.
</span>
</dd>
</dl>
<p>
</p>
</div>
<a name="reserved.variables.server.changelog"></a><div class="refsect1 changelog">
<h3 class="title">Changelog</h3>
<p class="para">
</p><table class="doctable informaltable">
<thead valign="middle">
<tr valign="middle">
<th>Version</th>
<th>Description</th>
</tr>
</thead>
<tbody valign="middle" class="tbody">
<tr valign="middle">
<td align="left">4.1.0</td>
<td align="left">
Introduced <var class="varname">$_SERVER</var> that deprecated
<var class="varname">$HTTP_SERVER_VARS</var>.
</td>
</tr>
</tbody>
</table>
<p>
</p>
</div>
<a name="reserved.variables.server.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 <var class="varname">$_SERVER</var> example</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'SERVER_NAME'</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
<div class="example-contents para"><p>The above example will output
something similar to:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
www.example.com
</pre></div>
</div>
</div><p>
</p>
</div>
<a name="reserved.variables.server.notes"></a><div class="refsect1 notes">
<h3 class="title">Notes</h3>
<blockquote><p><b class="note">Note</b>: This is a 'superglobal', or
automatic global, variable. This simply means that it is available in
all scopes throughout a script. There is no need to do
<strong class="command">global $variable;</strong> to access it within functions or methods.
<br /></p></blockquote>
</div>
<a name="reserved.variables.server.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="book.filter.php" class="link">The filter extension</a></li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>