Generally speaking, when building a website, a single entrance (mostly from index.php) will be used. In my opinion, the benefits of a single entrance include the following two points:
1. Subsequent programs can be processed uniformly. For example, if you want to use a third-party class library during development, you only need to introduce it in the entry file, and other programs will be able to reference it.
2. Paths can be processed uniformly. Because they all start from index.php, the imported file only needs to be relative to the path of index.php.
<?php $_SERVER['REQUEST_TIME']; // 得到请求开始时的时间戳 // eg. 1522674026 $_SERVER['HTTP_HOST']; // 当前请求的 Host: 头部的内容 // eg. test.php.cn $_SERVER['SERVER_NAME']; // 服务器主机的名称 // eg. test.php.cn $_SERVER['SERVER_PORT']; // 服务器所使用的端口 // eg. 80 $_SERVER['DOCUMENT_ROOT']; // 网站运行环境目录 // eg. /home/wwwroot/test.php.cn $_SERVER['SCRIPT_FILENAME']; // 当前执行脚本的绝对路径名 // eg./home/wwwroot/test.php.cn/01.php $_SERVER['HOME']; // php运行环境目录 // eg. /home/www $_SERVER['HTTP_ACCEPT_LANGUAGE']; // 浏览器语言 // eg. zh-CN,zh;q=0.9 $_SERVER['HTTP_ACCEPT_ENCODING']; // 当前请求的 Accept-Encoding: 头部的内容 // eg. gzip, deflate $_SERVER['HTTP_ACCEPT']; // 网站运行环境目录 // eg. text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 $_SERVER['HTTP_USER_AGENT']; // 当前请求的 User_Agent: 头部的内容。 // eg. Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36 $_SERVER['SERVER_SOFTWARE']; // 服务器标识的字串 // eg.nginx/1.12.1 $_SERVER['GATEWAY_INTERFACE']; // CGI 规范的版本 // eg. CGI/1.1 $_SERVER['SERVER_PROTOCOL']; // 请求页面时通信协议的名称和版本 // eg. HTTP/1.1 $_SERVER['REQUEST_METHOD']; // 访问页面时的请求方法 // eg.GET $_SERVER['PHP_SELF']; // 正在执行脚本的文件名 // eg./01.php
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of Simply record PHP's superglobal variable $_SERVER. For more information, please follow other related articles on the PHP Chinese website!