$_server is a very useful hyper-global variable in PHP, which can be helpful when developing portable Web sites.
I'll take a look at some of the variables I've used myself.
1.$_server[' server_name ': Records the domain name of the website.
2.$_server[' Document_root ': The root directory of the website (that is, the absolute path under your system, in Windows, such as C://wamp/www, Linux, for example, is/var/www/html).
3.$_server[' server_addr ': Record the IP address of the website
4.$_server[' REMOTE_ADDR ': Record the IP address of the visitor
5.$_server[' script_filename ': path to the file accessed
6.$_server[' request_scheme ': How to access the file, common for HTTP
In general, in the construction of the station, will use a single entrance (see more as from the index.php) Form, in my opinion, the advantages of a single entrance to the following two points:
1. The following procedures can be unified processing, such as the development time to use a third-party class library, only to be introduced in the portal file, the rest of the program will be able to reference
2. The path can be handled uniformly. Since all are starting from index.php, the introduction of the file as long as the path relative to index.php.
Individuals have developed discuz and WordPress two times, found that they all have a common point is that they will be unified in the beginning of the initial definition of the absolute path, so in the future when the introduction of other files will be very convenient, but also have portability.
About the root directory of the website, for a chestnut
Discuz defines the root directory discuz_root of the site in source/class/class_core.php,
It is defined in this way:
Define substr (dirname(__file__), 0,-12));
__FILE__ represents the path of the current file, DirName (__file__) represents the root directory of the current file, substr (DirName (__file__), 0, 12) to intercept the preceding characters, not the last 12, just good is source/ Class this 12 characters. My site is/var/www/html/discuz/source/class/class_core.php, after such a processing, discuz site root directory is/var/www/html/discuz/, It looks complicated, but it's easy to figure out for yourself.
WordPress defines the site root directory abspath in Wp-configs.
Direct more convenient:
Define dirname (__file__). ‘/‘);
and in order to facilitate the front-end Web development, I will also preface define a domain absolute path, what is the absolute path of the domain name? is to take WordPress, for example, http://localhost/wordpress/index.php/2016/10/31/001.html this page, then his domain is the absolute root directory is http://localhost/ wordpress/, the introduction of pictures later only need to be relatively in the root directory of WordPress to introduce the image, after the transplant to other servers, it will not affect, because this domain name absolute path is in the program when the definition of the run. This domain root directory is in the above site root directory to improve.
Only need to change the site's root directory to the domain name, the rest of the same, the first add a request is perfect.
Example: The site root directory is/var/www/html/wordpress/and changed to http://www.domain.com/wordpress/
Define $_server [' Request_scheme ']. ':/ /‘. Str_replace ($_server$_server[' server_name '], abspath));
Record PHP's hyper-global variables $_server