PHP obtains the path, name, and server path of the operating file before the current period.

Source: Internet
Author: User
Tags http authentication http digest authentication
PHP obtains the path, name, and server path of the file running before the current period. & lt ;? Phpecho "shows the relative path and file name of the script file :\"". $ _ SERVER ["PHP_SELF"]. "\" & lt; br & gt; "; echo" display the CGI script specifications used by the server :\"". $ _ SERVER ["GATEWAY_INTERFACE"]. "\ PHP obtains the path, name, and server path of the file running before the current period.

Echo "show the relative path and file name of the script file: \" ". $ _ SERVER [" PHP_SELF "]." \"
";
Echo "display CGI script specifications 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 "display the name of the currently running script SERVER: \" ". $ _ SERVER [" SERVER_NAME "]." \"
";
Echo "display the current running script server id: \" ". $ _ SERVER [" SERVER_SOFTWARE "]." \"
";
Echo "display the name and version of the communication protocol on the request page: \" ". $ _ SERVER [" SERVER_PROTOCOL "]." \"
";
Echo "request method for access page display: \" ". $ _ SERVER [" REQUEST_METHOD "]." \"
";
Echo "show script start Running time: \" ". $ _ SERVER [" REQUEST_TIME "]." \"
";
Echo "string after the URL question mark is displayed: \" ". $ _ SERVER [" QUERY_STRING "]." \"
";
Echo "shows the root directory of the current script: \" ". $ _ SERVER [" DOCUMENT_ROOT "]." \"
";
Echo "display the current Accept request header information: \" ". $ _ SERVER [" HTTP_ACCEPT "]." \"
";
Echo "display the character information of the current request: \" ". $ _ SERVER [" HTTP_ACCEPT_CHARSET "]." \"
";
Echo "displays the Accept-Encoding header information of the current request: \" ". $ _ SERVER [" HTTP_ACCEPT_ENCODING "]." \"
";
Echo "the Accept-Language header of the current request is displayed: \" ". $ _ SERVER [" HTTP_ACCEPT_LANGUAGE "]." \"
";
Echo "display the Connection header information of the current request: \" ". $ _ SERVER [" HTTP_CONNECTION "]." \"
";
Echo "displays the Host header information of the current request: \" ". $ _ SERVER [" HTTP_HOST "]." \"
";
Echo "shows the URL of the previous page: \" ". $ _ SERVER [" HTTP_REFERER "]." \"
";
Echo "display the current request's User-Agent header information: \" ". $ _ SERVER [" HTTP_USER_AGENT "]." \"
";
Echo "show whether the script can be accessed through HTTPS: \" ". $ _ SERVER [" HTTPS "]." \"
";
Echo "display the IP address of the user browsing the current page: \" ". $ _ SERVER [" REMOTE_ADDR "]." \"
";
Echo "show the host name of the user browsing the current page: \" ". $ _ SERVER [" REMOTE_HOST "]." \"
";
Echo "display the port used by the user to connect to the SERVER: \" ". $ _ SERVER [" REMOTE_PORT "]." \"
";
Echo "displays the absolute path name of the currently executed script: \" ". $ _ SERVER [" SCRIPT_FILENAME "]." \"
";
Echo "shows SERVER_ADMIN parameter settings in the Apache configuration file: \" ". $ _ SERVER [" SERVER_ADMIN "]." \"
";
Echo "displays the port used by the network SERVER. the default value is \" 80 \ ": \" ". $ _ SERVER [" SERVER_PORT "]." \"
";
Echo "display the SERVER version and virtual host name string: \" ". $ _ SERVER [" SERVER_SIGNATURE "]." \"
";
Echo "display the basic path of the script in the file system: \" ". $ _ SERVER [" PATH_TRANSLATED "]." \"
";
Echo "shows the path of the current script: \" ". $ _ SERVER [" SCRIPT_NAME "]." \"
";
Echo "shows the URI used to access the current page: \" ". $ _ SERVER [" REQUEST_URI "]." \"
";
?>

Note :?It is used in PHP 4.1.0 and later versions. In earlier versions, how does one use?$ HTTP_SERVER_VARS.

$ _ SERVER? Is an array containing header information, path, and script locations. The object of the array is created by the web server. It is not guaranteed that all servers can generate all information. the server may ignore some information or generate new information not listed below. This means that a large number of these variables are described in the CGI 1.1 specification, so we should take a closer look.

This is a "superglobal", or it can be described as an automatic global variable. This only means that it is valid in all scripts. Do not need to be used in functions or methods?Global $ _ SERVER;? Accessing it is like using it?$ HTTP_SERVER_VARS? Same.

$ HTTP_SERVER_VARS? It contains the same information, but is not an automatic global variable (note:$ HTTP_SERVER_VARS? And$ _ SERVER? Are different variables, and PHP processes them differently ).

If the register_globals command is set, these variables are also available in all scripts. that is, are the variables separated?$ _ SERVER? And$ HTTP_SERVER_VARS? Array. For more information, see the security section using Register Globals. These independent global variables are not automatic global variables.

Some $ _ SERVER elements listed below may be unavailable. Note: If you run PHP in the command line mode, the elements listed below are hardly valid (or have no practical significance ).

?

?

" PHP_SELF"

The file name of the script being executed, which is related to document root. For exampleHttp://example.com/test.php/foo.bar? ?$ _ SERVER ['php _ SELF ']? You will get/Test. php/foo. bar? This result. The _ FILE _ constant contains the absolute path and FILE name of the current (such as include) FILE.

If PHP runs as a command line, this variable is invalid before PHP 4.3.0.

" Argv"

Parameters passed to the script. When the script runs in the command line mode, the argv variable is passed to the command line parameters in the C language style of the program. When the GET method is called, the variable contains the requested data.

" Argc"

Contains the number of command line parameters passed to the program (if it is in command line mode ).

" GATEWAY_INTERFACE"

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

" SERVER_NAME"

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

" SERVER_SOFTWARE"

The string identified by the server, which is provided in the header information in the response request.

" SERVER_PROTOCOL"

The name and version of the communication protocol on the request page. For example,HTTP/1.0".

" REQUEST_METHOD"

The request method used to access the page. For example:"GET","HEAD","POST","PUT".

Note :?What is the request method?HEAD, The PHP script stops sending the header information (this means that no output buffer is available after any output is generated ).

" REQUEST_TIME"

The start time of the request. Valid from PHP 5.1.0.

" QUERY_STRING"

Query string (the first question mark in the URL? ).

" DOCUMENT_ROOT"

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

" HTTP_ACCEPT"

Current request?Accept:? Header information.

" HTTP_ACCEPT_CHARSET"

Current request?Accept-Charset:? Header information. For example:"ISO-8859-1, *, UTF-8".

" HTTP_ACCEPT_ENCODING"

Current request?Accept-Encoding:? Header information. For example:"Gzip".

" HTTP_ACCEPT_LANGUAGE"

Current request?Accept-Language:? Header information. For example:"En".

" HTTP_CONNECTION"

Current request?Connection:? Header information. For example:"Keep-Alive".

" HTTP_HOST"

Current request?Host:? Header information.

" HTTP_REFERER"

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

" HTTP_USER_AGENT"

Current request?User-Agent:? Header information. This 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 it be used?Get_browser ()? Obtain this information.

" HTTPS"

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

" REMOTE_ADDR"

Browsing the IP address of the user on the current page.

" REMOTE_HOST"

The host name of the user browsing the current page. What is reverse domain name resolution based on this user?REMOTE_ADDR.

Note :?You must configure the Web server to create this variable. For example, Apache needs?Httpd. conf? InHostnameLookups On. See?Gethostbyaddr ().

" REMOTE_PORT"

The port used by the user to connect to the server.

" SCRIPT_FILENAME"

The absolute path name of the currently executed script.

Note :?If the script is executed in the CLI as a relative path, for example?File. php? Or../File. php,$ _ SERVER ['script _ filename']? It will contain the relative path specified by the user.

?

" SERVER_ADMIN"

This value specifies the SERVER_ADMIN parameter in the Apache server configuration file. If the script runs on a VM, this value is the value of that VM.

" SERVER_PORT"

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

" SERVER_SIGNATURE"

A string containing the server version and virtual host name.

" PATH_TRANSLATED"

The basic path of the file system (not the document root directory) where the current script is located. This is the result of a virtual image to a real path on the server.

Note :?After PHP 4.3.2,PATH_TRANSLATED? In Apache 2? SAPI? If Apache does not generate this value, PHP will generate it and put the value in?SCRIPT_FILENAME? Server constant. Does this change comply? CGI? Specification,PATH_TRANSLATED? Only in?PATH_INFO? The specified condition exists.

What can be used by Apache 2 users?Httpd. conf? In?AcceptPathInfo On? To define?PATH_INFO.

" SCRIPT_NAME"

The path that contains 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, including the FILE ).

" REQUEST_URI"

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

" PHP_AUTH_DIGEST"

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

" PHP_AUTH_USER"

When PHP runs in the Apache or IIS (PHP 5 is an ISAPI) module and is using the HTTP authentication function, this variable is the user input username.

" PHP_AUTH_PW"

When PHP runs in the Apache or IIS (PHP 5 is an ISAPI) module and is using the HTTP authentication function, this variable is the password entered by the user.

" AUTH_TYPE"

When PHP runs in the Apache module mode and uses the HTTP authentication function, this variable is the authentication type.

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.