PHP server Variable $_server

Source: Internet
Author: User
Tags http authentication http digest authentication php server

PHP $_server variables

$_server is an array that contains such things as header information (header), path, and script location (scripts locations). It is a super global variable in PHP, and we can access it directly from anywhere in the PHP program.

$_server contains a lot of information, you can try to print it directly:

Print_r ($_server);

is limited to space, the results of printing are no longer listed here, and the results printed on different servers are also varied.

$_server array elements

In more cases, we only need to $_server some elements in the array (array cells). The $_server array contains the following elements:

Page Program Related
  • $_server[' php_self ': relative to the root directory of the Web site and the PHP program name, and document root related.
  • $_server[' Http_referer ': The URL address of the previous page linked to the current page.
  • $_server[' script_name ': The path to the root directory of the Web site and the PHP program file name.
  • $_server[' Request_uri ']: the URI required to access this page.
  • $_server[' script_filename ': the absolute path and file name of the currently running PHP program.
  • $_server[' path_translated ': The basic path of the file system (not the document root) where the current PHP program resides.
  • $_server[' query_string ': query string (the first question mark in the URL?) Content that follows but does not include the following #).
  • $_server[' argv ': parameters passed to the current PHP program.
  • $_server[' argc ': in command-line mode, contains the number of command-line arguments passed to the program.
  • $_server[' request_time ': Timestamp at the start of the request, valid from PHP 5.1.0.
  • $_server[' Request_method ': The method of requesting access to a page, for example:, POST or PUT.
  • $_server[' http_accept ': The current request's ACCEPT: The contents of the header information.
  • $_server[' Http_accept_charset ': The Accept-charset of the current request: the contents of the header information. For example: "Iso-8859-1,*,utf-8".
  • $_server[' http_accept_encoding ': The accept-encoding of the current request: the contents of the header information. For example: "gzip".
  • $_server[' http_accept_language ': The accept-language of the current request: the contents of the header information. For example: "ZH-CN".
  • $_server[' http_connection ': The CONNECTION of the current request: the contents of the header information. For example: "Keep-alive".
  • $_server[' http_host ': The current requested HOST: The contents of the header information.
  • $_server[' HTTPS ']: If the PHP program is accessed through the HTTPS protocol, it is set to a non-null value.
  • $_server[' php_auth_digest ': When running as an Apache module, this variable is set to the "Authorization" HTTP header content sent by the client (for further authentication operations) during HTTP DIGEST authentication.
  • $_server[' php_auth_user ': When PHP is running in Apache or IIS (PHP 5 is an ISAPI) module, and HTTP authentication is being used, this variable is the user name entered by the user.
  • $_server[' PHP_AUTH_PW ': When PHP is running in Apache or IIS (PHP 5 is an ISAPI) module, and HTTP authentication is being used, this variable is the password entered by the user.
  • $_server[' Auth_type ': When PHP is running in the Apache module mode and is using HTTP authentication, this variable is the type of authentication.
Server-Side related
    • $_server[' Document_root ': The document root directory where the PHP program is currently running, as defined in the server configuration file.
    • $_server[' Gateway_interface ': The version of the CGI specification used by the server, for example: "cgi/1.1".
    • $_server[' server_addr ': The IP address of the server where the PHP program is currently running.
    • $_server[' server_name ': The name of the server on which the PHP program is currently running.
    • $_server[' Server_admin ']:apache the server_admin parameter in the server configuration file.
    • $_server[' Server_port ': The port used by the server. If SSL secured connection is used, this value is the HTTP port set by the user.
    • $_server[' server_signature ': A string containing the server version and the virtual host name.
    • $_server[' Server_software ': The server-identified string, given in the header information in response to the request.
    • $_server[' Server_protocol ': The name and version of the communication protocol when the page is requested, for example: "http/1.0".
Other miscellaneous
    • $_server[' http_user_agent ': The user-agent of the current request: the contents of the header information that indicates the user agent who accessed the page.
    • $_server[' REMOTE_ADDR ': Browsing the current page user's IP address.
    • $_server[' Remote_host ': Browsing the host name of the current page user.
    • $_server[' Remote_port ': The port used by the user when connecting to the server.

Note that if you run PHP as a command line, the elements listed above are almost no valid (or meaningless).

PHP server Variable $_server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.