Today, we introduce is related to the PHP function to get the current url of the specific method, the understanding of the function method, and further deepen our understanding of the PHP language, improve our learning.
Instance constructor PHP 5.0 PHP to get the current url to explain the specific methods are as follows:
$ Url_this = "'http://'. $ _SERVER ['SERVER_NAME'].':'.$_ SERVER [" SERVER_PORT "].$_ SERVER ["REQUEST_URI"];;
echo $ url_this;
Shows: http://localhost/drupaluser/index.php
Server variables: $ _SERVER
Note: In PHP 4.1.0 and later use.The previous version, use $ HTTP_SERVER_VARS.
$ _SERVER Is a very inclusive, such as head (headers), path (paths) and script location (scrīpt locations) of the array.Array by a web server created entity.Can not guarantee that all servers can produce all of the information; server may ignore some information, or produce a number is not listed in the following new information.This means that a large number of these variables is described in the CGI 1.1 specification, so you should study it carefully.
This is a "superglobal", or global variable can be described as automatic.This simply means that it is in all of the scripts are valid.In the function or method you do not need to use 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 in different ways.)
If the register_globals directive is set, these variables are all available in the script; that is, separate the $ _SERVER and $ HTTP_SERVER_VARS arrays.Information, see the security chapter titled Using Register Globals.These single global variable global variable is not automatic.
You might find the following elements are listed some of the $ _SERVER is not available.Note that if you run a command line PHP, the elements listed below is almost no effective (or no practical significance.)
"PHP_SELF"
Currently executing script file name associated with the document root.For example, the script URL address http://example.com/test.php/foo.bar use $ _SERVER ['PHP_SELF'] will be / test.php / foo.bar this result.
If the command line to run PHP, the variable is invalid.
"Argv"
The parameters passed to the script.When the script runs when the command line, argv variable is passed to the program C-style command line arguments.When you call the GET method, the variable contains the requested data.
"Argc"
Contains the command line passed to the program the number of parameters (if running in command line mode).
"GATEWAY_INTERFACE"
CGI specification used by the server version.For example, "CGI/1.1".
'SERVER_NAME'
Current script server host name.If the script is running on a virtual host, the name is set by a virtual host that the value of the decision.
'SERVER_SOFTWARE'
Server identification string, in response to requests given in the head.
"SERVER_PROTOCOL"
Communication protocol when the requested page name and version.For example, "HTTP/1.0".
"REQUEST_METHOD"
When the request method to access the page.For example: "GET", "HEAD", "POST", "PUT".
"QUERY_STRING"
Query (query) string.
"DOCUMENT_ROOT"
Where the current script document root directory.Defined in the server configuration file.
"HTTP_ACCEPT"
The current request Accept: header content.
"HTTP_ACCEPT_CHARSET"
The current request Accept-Charset: header content.For example: "iso-8859-1, *, utf-8".
"HTTP_ACCEPT_ENCODING"
The current request Accept-Encoding: header content.For example: "gzip".
"HTTP_ACCEPT_LANGUAGE"
The current request Accept-Language: header content.For example: "en".
"HTTP_CONNECTION"
The current request Connection: the contents of the head.For example: "Keep-Alive".
"HTTP_HOST"
The current request Host: header content.
"HTTP_REFERER"
Link to the current page's URL address of the previous page.Not all of the user agent (browser) will set this variable, and some can also manually modify the HTTP_REFERER.Therefore, this variable is not always true true.
"HTTP_USER_AGENT"
The current request User_Agent: the contents of the head.The string that the user agent to access the page information.A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586).You can also use the get_browser () to get this information.
"REMOTE_ADDR"
Users browsing the IP address of the current page.
'REMOTE_HOST'
View the current page is the user's host name.Reverse DNS is based on the user's REMOTE_ADDR.
Note: You must configure the Web server to create this variable.For example, in Apache httpd.conf need HostnameLookups On.See also gethostbyaddr ().
"REMOTE_PORT"
When a user connects to the server port to use.
"Scrīpt_FILENAME"
The currently executing script's absolute path name.
"SERVER_ADMIN"
The value specified in the Apache server configuration file SERVER_ADMIN parameters.If the script is running on a virtual host, then the value is the value of the virtual host.
"SERVER_PORT"
Server port to use.The default is "80."If you use SSL secure connection, then this is the HTTP port you set.
"SERVER_SIGNATURE"
Containing the server version and virtual host name string.
"PATH_TRANSLATED"
File system where the current script (not document root) of the basic path.This is the server path to the virtual to the real image of the result.
"Scrīpt_NAME"
Contains the path of the current script.This page needs to point to themselves is very useful.
"REQUEST_URI"
Required to access this page URI.For example, "/ index.html".
"PHP_AUTH_USER"
When the PHP Apache module running mode, and are using HTTP authentication this variable is the user name entered by the user.
"PHP_AUTH_PW"
When the PHP Apache module running mode, and are using HTTP authentication this variable is the user password.
"AUTH_TYPE"
When the PHP Apache module running mode, and are using HTTP authentication this variable is the type of certification.