Here I would like to summarize some of the information that gets the URL in the address bar and my path to the file that it belongs to:
Using $_server[] We can do a lot of things: it's an array of headers (headers), path information, and script locations, and the entities of the array are created by the Web server.
This is a "superglobal", or it can be described as an automatic global variable. This simply means that it works in all scripts. You do not need to use global $_server in a function or method; Access it, just as you would with $HTTP _server_vars.
The $HTTP _server_vars contains the same information, but is 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 also available in all scripts, that is, the $_server and $HTTP _server_vars arrays are separated.
$_server[' Http_host ' gets the current requested HOST: header content
$_server[' php_self '] This is probably the most frequently used, it returns the file name of the page that is currently being invoked, and if it is http://localhost/test/2005/test.php, it will return/test/2005/ test.php
$_server[' Script_name '] it will return the path containing the current script. This is useful when the page needs to point to itself
$_server[' Script_filename '] it will return the absolute path information where the current file is located
$_server[' Request_uri ' returns the URI required to access this page, including the "/"
There are, of course, many path functions:
DirName (), returns the section of the directory in the path information, preceded by a "/"
BaseName () returns the basic file name portion of the path, and can, of course, set the suffix to control the output.
Realpath (), returns the absolutely normalized path of the path information