PHP gets the path of the file before the current period, name, server path

Source: Internet
Author: User
Tags http authentication http digest authentication
PHP gets the path, name, and server path of the running file before the current period

echo "Displays the relative path and file name of the script file: \" ". $_server[" Php_self "]." \"
";
echo "Displays the CGI script specification used by the server: \" ". $_server[" Gateway_interface "]." \"
";
echo "Displays the IP address of the server where the script is currently running: \" ". $_server[" Server_addr "]." \"
";
echo "Displays the currently running Script server name: \" ". $_server[" SERVER_NAME "]." \"
";
echo "Displays the currently running Script server identity: \" ". $_server[" Server_software "]." \"
";
echo "Displays the name and version of the communication protocol for the requested page: \" ". $_server[" Server_protocol "]." \"
";
echo "Displays the request method for accessing the page: \" ". $_server[" Request_method "]." \"
";
echo "Show script start run time: \" ". $_server[" Request_time "]." \"
";
echo "Displays the string after the URL question mark: \" ". $_server[" Query_string "]." \"
";
echo "Displays the document root of the currently running script: \" ". $_server[" Document_root "]." \"
";
echo "Displays the header information for the current ACCEPT request: \" ". $_server[" Http_accept "]." \"
";
echo "Displays the character information for the current request: \" ". $_server[" Http_accept_charset "]." \"
";
echo "Displays the Accept-encoding header information for the current current request: \" ". $_server[" Http_accept_encoding "]." \"
";
echo "Displays the Accept-language header information for the current request: \" ". $_server[" Http_accept_language "]." \"
";
echo "Displays the CONNECTION header information for the current request: \" ". $_server[" Http_connection "]." \"
";
echo "Displays the HOST header information for the current request: \" ". $_server[" Http_host "]." \"
";
echo "Displays the URL address of the previous page of the current page: \" ". $_server[" Http_referer "]." \"
";
echo "Displays the header information for the user-agent of the current request: \" ". $_server[" Http_user_agent "]." \"
";
echo "shows if the script can be accessed through the HTTPS protocol: \" ". $_server[" https "]." \"
";
echo "Displays the IP address of the user browsing the current page: \" ". $_server[" REMOTE_ADDR "]." \"
";
echo "Displays the host name of the user browsing the current page: \" ". $_server[" Remote_host "]." \"
";
echo "shows the port used by the user when connecting to the server: \" ". $_server[" Remote_port "]." \"
";
echo "Displays the absolute path name of the currently executing script: \" ". $_server[" Script_filename "]." \"
";
echo "Displays the Server_admin parameter settings in the Apache configuration file: \" ". $_server[" Server_admin "]." \"
";
echo "shows the port used by the network server, which defaults to \" 80\ ": \" ". $_server[" Server_port "]." \"
";
echo "Displays the server version and the virtual hostname of the string: \" ". $_server[" Server_signature "]." \"
";
echo "shows the basic path of the script in the file system: \" ". $_server[" path_translated "]." \"
";
echo "Displays the path of the current script: \" ". $_server[" Script_name "]." \"
";
echo "shows access to the current page uri:\" ". $_server[" Request_uri "]." \"
";
?>

Note:? Used in PHP 4.1.0 and later versions. Previous version, use? $HTTP_SERVER_VARS .

$_SERVER? is an array that contains the header information (header), path, and script location (scripts locations). The entity of the array is created by the Web server. There is no guarantee that all servers will generate all the information; the server may have ignored some information or generated some new information that is not listed below. This means that a large number of these variables are described in the CGI 1.1 specification, so it should be studied carefully.

This is a "superglobal", or can be described as an automatic global variable. This simply means that it works in all scripts. Do you want to use it in a function or method? global $_server;? Access it, just like using? $HTTP_SERVER_VARS ? The same.

$HTTP_SERVER_VARS? contains the same information, but not an automatic global variable (note: $HTTP_SERVER_VARS ? and $_SERVER ? are different variables, PHP handles them differently).

If the register_globals directive is set, these variables are also available in all scripts; $_SERVER and $HTTP_SERVER_VARS ? arrays. For related information, please refer to the section on security using Register Globals. These individual global variables are not automatic global variables.

You may find that some of the $_server elements listed below are not available. Note that if you run PHP as a command line, the elements listed below are almost no valid (or meaningless).

?

?

" PHP_SELF "

The file name of the currently executing script, which is related to document root. For example, in a script with a URL address of Http://example.com/test.php/foo.bar?? $_SERVER['PHP_SELF'] Will get /test.php/foo.bar? This result. The __FILE__ constant contains the absolute path and file name of the current (for example, the containing) file.

If PHP is run as a command line, the variable is not valid until PHP 4.3.0.

" argv "

The arguments passed to the script. When the script runs in command-line mode, the ARGV variable is passed to the program's C-language style command-line arguments. When the GET method is called, the variable contains the requested data.

" argc "

Contains the number of command-line arguments passed to the program (if run in command-line mode).

" GATEWAY_INTERFACE "

The version of the CGI specification used by the server. For example, " CGI/1.1 ".

" SERVER_NAME "

The name of the server host where the script is currently running. If the script is running on a virtual host, the name is determined by the value set by that virtual host.

" SERVER_SOFTWARE "

The string that the server identifies is given in the header information in response to the request.

" SERVER_PROTOCOL "

The name and version of the communication protocol when the page is requested. For example, " HTTP/1.0 ".

" REQUEST_METHOD "

The request method when the page is accessed. For example: "," GET HEAD "," "," POST PUT ".

Note:? If the request is in the same way HEAD , the PHP script will abort after the message is sent (which means that no output buffers are available after any output has been generated).

" REQUEST_TIME "

Timestamp at the start of the request. Valid from PHP 5.1.0.

" QUERY_STRING "

(query) string (the first question mark in the URL?) After the content).

" DOCUMENT_ROOT "

The document root directory where the script is currently running. Defined in the server configuration file.

" HTTP_ACCEPT "

The current request? Accept: ? The contents of the header information.

" HTTP_ACCEPT_CHARSET "

The current request? Accept-Charset: ? The contents of the header information. For example: " iso-8859-1,*,utf-8 ".

" HTTP_ACCEPT_ENCODING "

The current request? Accept-Encoding: ? The contents of the header information. For example: " gzip ".

" HTTP_ACCEPT_LANGUAGE "

The current request? Accept-Language: ? The contents of the header information. For example: " en ".

" HTTP_CONNECTION "

The current request? Connection: ? The contents of the header information. For example: " Keep-Alive ".

" HTTP_HOST "

The current request? Host: ? The contents of the header information.

" HTTP_REFERER "

The URL address of the previous page that links to the current page. Not all user agents (browsers) will set this variable, and some can also be manually modified? HTTP_REFERER Therefore, this variable is not always true and correct.

" HTTP_USER_AGENT "

The current request? User-Agent: ? The contents of the header information. The string indicates the information of the user agent accessing the page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586) . can also be used? get_browser ()? Get this information.

" HTTPS "

If the script is accessed through the HTTPS protocol, it is set to a non-null value.

" REMOTE_ADDR "

The IP address of the user who is browsing the current page.

" REMOTE_HOST "

The host name of the user who is browsing the current page. Reverse Domain name resolution is based on the user's? REMOTE_ADDR .

Note:? You must configure the WEB server to establish this variable. For example, Apache needs to be in? httpd.conf? There are HostnameLookups On . See? gethostbyaddr ().

" REMOTE_PORT "

The port that the user uses when connecting to the server.

" SCRIPT_FILENAME "

The absolute path name of the currently executing script.

Note:? If the script is executed in the CLI as a relative path, for example? file.php? or . /file.php, $_SERVER['SCRIPT_FILENAME'] ? will contain the user-specified relative path.

?

" SERVER_ADMIN "

This value indicates the Server_admin parameter in the Apache server configuration file. If the script is running on a virtual host, the value is the value of that virtual host.

" SERVER_PORT "

The port used by the server. The default is " 80 ". If SSL secured connection is used, this value is the HTTP port set by the user.

" SERVER_SIGNATURE "

A string containing the server version and the virtual host name.

" PATH_TRANSLATED "

The base path to the file system (not the document root) where the current script resides. This is the result of the server making a virtual-to-real-path image.

Note:? After PHP 4.3.2, PATH_TRANSLATED ? in Apache 2? SAPI? mode is no longer implicitly assigned as Apache 1, but if Apache does not generate this value, PHP generates it itself and puts its value into the? SCRIPT_FILENAME ? The server constant. Did this change follow? CGI specification, PATH_TRANSLATED only in the? PATH_INFO ? exist only under defined conditions.

Apache 2 users can use? httpd.conf?? AcceptPathInfo On To define? PATH_INFO .

" SCRIPT_NAME "

Contains the path to the current script. This is useful when the page needs to point to itself. __FILE__ contains the absolute path and file name of the current file (for example, include files).

" REQUEST_URI "

The URI required to access this page. For example, " /index.html ".

" PHP_AUTH_DIGEST "

When running as an Apache module, during HTTP Digest authentication, this variable is set to the "Authorization" HTTP header content sent by the client (for further authentication operations).

" PHP_AUTH_USER "

When PHP is running in Apache or IIS (PHP 5 is an ISAPI) module, and the HTTP authentication feature is being used, this variable is the user name entered by the user.

" PHP_AUTH_PW "

When PHP is running in Apache or IIS (PHP 5 is an ISAPI) module, and the HTTP authentication feature is being used, this variable is the password that the user entered.

" AUTH_TYPE "

This variable is the type of authentication when PHP is running in the Apache module mode and is using the HTTP authentication feature.

  • Related Article

    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.