Home > Article > Backend Development > Summary of PHP application path variable problems_PHP tutorial
Local server, domain name http://d.com, root path D:phpnowvhostsd.com.yii, the relative root directory has the file /x.php in the code requeir_once /a/a.php, and /a /a.phprequeir_once /a/b/b.php
/x.php
$_SERVER["HTTP_HOST"]: [d.com]//Host currently requested: domain name information
$_SERVER["PHP_SELF"]: [】//
$_SERVER["SCRIPT_NAME"]:【/x.php】 //
$_SERVER["SCRIPT_FILENAME"]: [D:/phpnow/vhosts/d.com.yii/x.php 】// of the actual execution file.
__FILE__: []// of the actual execution code.
$_SERVER["REQUEST_URI"]: [/x.php/x/y/z.html?a=b&c=d]//The url request includes all content after / and after.
$_SERVER["QUERY_STRING"]: [a=b&c=d] //The content after ? in the url request.
$_SERVER["DOCUMENT_ROOT"]: [D:/phpnow/vhosts/d.com.yii]//Document root directory. Define
basename($_SERVER["PHP_SELF"]) in the server configuration file: []// to execute the file 🎜>basename($_SERVER["SCRIPT_NAME"]): [x.php] //basename($_SERVER["SCRIPT_FILENAME" ]): [x.php]//’s basename(__FILE__): []//'s
dirname($_SERVER["PHP_SELF"]): []//'s dirname($_SERVER["SCRIPT_NAME"]): []//'s dirname($_SERVER["SCRIPT_FILENAME"]): [D:/phpnow/vhosts/d.com.yii]// is located dirname(__FILE__) : []//'s
require_once /a/a.php
$_SERVER["HTTP_HOST"]: [d.com]//Host currently requested: domain name information
/a/a.php $_SERVER["HTTP_HOST"]: [d.com]//Host currently requested: domain name information $_SERVER["HTTP_HOST"]: [d.com]//Host currently requested: domain name information
/x.php /a/a.php /a/b/php
$_SERVER["PHP_SELF"]: [】//$_SERVER["SCRIPT_NAME"]:【/x.php】 //$_SERVER["SCRIPT_FILENAME"]: [D:/phpnow/vhosts/d.com.yii/x.php 】// of the actual execution file. __FILE__: []// of the actual execution code.
$_SERVER["REQUEST_URI"]: [/x.php/x/y/z.html?a=b&c=d]//The url request includes all content after / and after.
$_SERVER["QUERY_STRING"]: [a=b&c=d] //The content after ? in the url request.
$_SERVER["DOCUMENT_ROOT"]: [D:/phpnow/vhosts/d.com.yii]//Document root directory. Define
basename($_SERVER["PHP_SELF"]) in the server configuration file: []// to execute the file 🎜>basename($_SERVER["SCRIPT_NAME"]): [x.php] //
basename($_SERVER["SCRIPT_FILENAME" ]): [x.php]//’s basename(__FILE__): []//'s dirname($_SERVER["PHP_SELF"]): []//'s dirname($_SERVER["SCRIPT_NAME"]): []//'s dirname($_SERVER["SCRIPT_FILENAME"]): [D:/phpnow/vhosts/d.com.yii]// is located
dirname(__FILE__) :[]//'s require_once /a/b/b.php
$_SERVER["PHP_SELF"]: []//
$_SERVER["SCRIPT_NAME"]:【/x.php】//
$_SERVER["SCRIPT_FILENAME"]:[D:/ phpnow/vhosts/d.com.yii/x.php】//.
__FILE__: []//.
$_SERVER["REQUEST_URI"]: [/x.php/x/y/z.html?a=b&c=d]//The url request includes all content after / and after.
$_SERVER["QUERY_STRING"]: [a=b&c=d] //The content after ? in the url request.
$_SERVER["DOCUMENT_ROOT"]: [D:/phpnow/vhosts/d.com.yii]//Document root directory. Define
basename($_SERVER["PHP_SELF"]) in the server configuration file: []//'s
basename($_SERVER["SCRIPT_NAME"]) :[x.php]//'s
basename($_SERVER["SCRIPT_FILENAME"]): [x.php]//'s
basename(__FILE__) :【】//'s
dirname($_SERVER["PHP_SELF"]): [】//'s
dirname ($_SERVER["SCRIPT_NAME"]):【】//'s
dirname($_SERVER["SCRIPT_FILENAME"]):【D:/phpnow/vhosts/d.com.yii】/ /'s
dirname(__FILE__): []//'s
$_SERVER["PHP_SELF"]: []//
$_SERVER["SCRIPT_NAME"]:【/a/a.php】//
$_SERVER["SCRIPT_FILENAME"]:[D :/phpnow/vhosts/d.com.yii/a/a.php】//.
__FILE__: []//.
$_SERVER["REQUEST_URI"]: [/a/a.php/x/y/z.html?a=b&c=d]//The url request includes / and everything after it.
$_SERVER["QUERY_STRING"]: [a=b&c=d] //The content after ? in the url request.
$_SERVER["DOCUMENT_ROOT"]: [D:/phpnow/vhosts/d.com.yii]//Document root directory. Define
basename($_SERVER["PHP_SELF"]) in the server configuration file: []//'s
basename($_SERVER["SCRIPT_NAME"]) :[a.php]//’s
basename($_SERVER["SCRIPT_FILENAME"]): [a.php]//’s
basename(__FILE__) :【】//'s
dirname($_SERVER["PHP_SELF"]): [】//'s
dirname ($_SERVER["SCRIPT_NAME"]):[/a]//'s
dirname($_SERVER["SCRIPT_FILENAME"]):[D:/phpnow/vhosts/d.com.yii /a】//’s
dirname(__FILE__):【】//’s
require_once /a/b/b.php
$_SERVER["PHP_SELF"]: []//
$_SERVER["SCRIPT_NAME"]:【/a/a.php】//
$_SERVER["SCRIPT_FILENAME"]:[D :/phpnow/vhosts/d.com.yii/a/a.php】//.
__FILE__: []//.
$_SERVER["REQUEST_URI"]: [/a/a.php/x/y/z.html?a=b&c=d]//The url request includes / and everything after it.
$_SERVER["QUERY_STRING"]: [a=b&c=d] //The content after ? in the url request.
$_SERVER["DOCUMENT_ROOT"]: [D:/phpnow/vhosts/d.com.yii]//Document root directory. Define
basename($_SERVER["PHP_SELF"]) in the server configuration file: []//'s
basename($_SERVER["SCRIPT_NAME"]) :[a.php]//’s
basename($_SERVER["SCRIPT_FILENAME"]): [a.php]//’s
basename(__FILE__) :【】//'s
dirname($_SERVER["PHP_SELF"]): [】//'s
dirname ($_SERVER["SCRIPT_NAME"]):[/a]//'s
dirname($_SERVER["SCRIPT_FILENAME"]):[D:/phpnow/vhosts/d.com.yii /a】//’s
dirname(__FILE__):【】//’s<?<span php
</span><span echo</span> "<br/>/x.php<hr/>"<span ;
</span><span echo</span> '$_SERVER["HTTP_HOST"]:【',<span $_SERVER</span>['HTTP_HOST'],"】//当前请求的 Host:即域名信信息","<br/>"<span ;
</span><span echo</span> '<br/>'<span ;
</span><span echo</span> '$_SERVER["PHP_SELF"]:【<font color="#EE00EE">',<span $_SERVER</span>['PHP_SELF'],"</font>】//<font color='green'>请求执行文件的</font><font color='red'>相对</font><font color='blue'>地址</font>","<br/>"<span ;
</span><span echo</span> '$_SERVER["SCRIPT_NAME"]:【',<span $_SERVER</span>['SCRIPT_NAME'],"】//<font color='green'>实际执行文件</font><font color='red'>相对</font><font color='blue'>地址</font>","<br/>"<span ;
</span><span echo</span> '$_SERVER["SCRIPT_FILENAME"]:【',<span $_SERVER</span>['SCRIPT_FILENAME'],"】//<font color='green'>实际执行文件的</font><font color='red'>绝对</font><font color='blue'>路径</font>。","<br/>"<span ;
</span><span echo</span> '__FILE__ :【<font color="#EE00EE">',<span __FILE__</span> ,"</font>】//<font color='green'>实际执行代码的</font><font color='red'>绝对</font><font color='blue'>路径</font>。","<br/>"<span ;
</span><span echo</span> '<br/>'<span ;
</span><span echo</span> '$_SERVER["REQUEST_URI"]:【',<span $_SERVER</span>['REQUEST_URI'],"】//url请求中包括/和之后的所有内容。","<br/>"<span ;
</span><span echo</span> '$_SERVER["QUERY_STRING"]:【',<span $_SERVER</span>['QUERY_STRING'],"】//url请求中?之后的内容。","<br/>"<span ;
</span><span echo</span> '<br/>'<span ;
</span><span echo</span> '$_SERVER["DOCUMENT_ROOT"]:【',<span $_SERVER</span>['DOCUMENT_ROOT'],"】//文档根目录。在服务器配置文件中定义","<br/>"<span ;
</span><span echo</span> "<br/>"<span ;
</span><span echo</span> 'basename($_SERVER["PHP_SELF"]):【<font color="#EE00EE">',<span basename</span>(<span $_SERVER</span>['PHP_SELF']),"</font>】//<font color='green'>请求执行文件的</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span echo</span> 'basename($_SERVER["SCRIPT_NAME"]):【',<span basename</span>(<span $_SERVER</span>['SCRIPT_NAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span echo</span> 'basename($_SERVER["SCRIPT_FILENAME"]):【',<span basename</span>(<span $_SERVER</span>['SCRIPT_FILENAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span echo</span> 'basename(__FILE__):【<font color="#EE00EE">',<span basename</span>(<span __FILE__</span>),"</font>】//<font color='green'>实际执行代码</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span //</span><span echo 'basename($_SERVER["ORIG_SCRIPT_NAME"]):【',basename($_SERVER['ORIG_SCRIPT_NAME']),"】//如果PHP通过CGI来运行,这个变量的值就是/Php/Php.exe 如果Apache将PHP脚本作为模块来运行,该变量的值应该是/Phptest.php","<br/>";</span>
<span echo</span> "<br/>"<span ;
</span><span echo</span> 'dirname($_SERVER["PHP_SELF"]):【<font color="#EE00EE">',<span dirname</span>(<span $_SERVER</span>['PHP_SELF']),"</font>】//<font color='green'>请求执行文件的</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span echo</span> 'dirname($_SERVER["SCRIPT_NAME"]):【',<span dirname</span>(<span $_SERVER</span>['SCRIPT_NAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span echo</span> 'dirname($_SERVER["SCRIPT_FILENAME"]):【',<span dirname</span>(<span $_SERVER</span>['SCRIPT_FILENAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span echo</span> 'dirname(__FILE__):【<font color="#EE00EE">',<span dirname</span>(<span __FILE__</span>),"</font>】//<font color='green'>实际执行代码</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span //</span><span echo 'dirname($_SERVER["ORIG_SCRIPT_NAME"]):【',dirname($_SERVER['ORIG_SCRIPT_NAME']),"】//如果PHP通过CGI来运行,这个变量的值就是/Php/Php.exe 如果Apache将PHP脚本作为模块来运行,该变量的值应该是/Phptest.php","<br/>";</span>
<span echo</span> "<br/>"<span ;
</span><span echo</span> "require_once "<span ;
</span><span require_once</span>("a/a.php");
<?<span php
</span><span echo</span> "/a/a.php<hr/>"<span ;
</span><span echo</span> '$_SERVER["HTTP_HOST"]:【',<span $_SERVER</span>['HTTP_HOST'],"】//当前请求的 Host:即域名信信息","<br/>"<span ;
</span><span echo</span> '<br/>'<span ;
</span><span echo</span> '$_SERVER["PHP_SELF"]:【<font color="#EE00EE">',<span $_SERVER</span>['PHP_SELF'],"</font>】//<font color='green'>请求执行文件的</font><font color='red'>相对</font><font color='blue'>地址</font>","<br/>"<span ;
</span><span echo</span> '$_SERVER["SCRIPT_NAME"]:【',<span $_SERVER</span>['SCRIPT_NAME'],"】//<font color='green'>实际执行文件</font><font color='red'>相对</font><font color='blue'>地址</font>","<br/>"<span ;
</span><span echo</span> '$_SERVER["SCRIPT_FILENAME"]:【',<span $_SERVER</span>['SCRIPT_FILENAME'],"】//<font color='green'>实际执行文件的</font><font color='red'>绝对</font><font color='blue'>路径</font>。","<br/>"<span ;
</span><span echo</span> '__FILE__ :【<font color="#EE00EE">',<span __FILE__</span> ,"</font>】//<font color='green'>实际执行代码的</font><font color='red'>绝对</font><font color='blue'>路径</font>。","<br/>"<span ;
</span><span echo</span> '<br/>'<span ;
</span><span echo</span> '$_SERVER["REQUEST_URI"]:【',<span $_SERVER</span>['REQUEST_URI'],"】//url请求中包括/和之后的所有内容。","<br/>"<span ;
</span><span echo</span> '$_SERVER["QUERY_STRING"]:【',<span $_SERVER</span>['QUERY_STRING'],"】//url请求中?之后的内容。","<br/>"<span ;
</span><span echo</span> '<br/>'<span ;
</span><span echo</span> '$_SERVER["DOCUMENT_ROOT"]:【',<span $_SERVER</span>['DOCUMENT_ROOT'],"】//文档根目录。在服务器配置文件中定义","<br/>"<span ;
</span><span echo</span> "<br/>"<span ;
</span><span echo</span> 'basename($_SERVER["PHP_SELF"]):【<font color="#EE00EE">',<span basename</span>(<span $_SERVER</span>['PHP_SELF']),"</font>】//<font color='green'>请求执行文件的</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span echo</span> 'basename($_SERVER["SCRIPT_NAME"]):【',<span basename</span>(<span $_SERVER</span>['SCRIPT_NAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span echo</span> 'basename($_SERVER["SCRIPT_FILENAME"]):【',<span basename</span>(<span $_SERVER</span>['SCRIPT_FILENAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span echo</span> 'basename(__FILE__):【<font color="#EE00EE">',<span basename</span>(<span __FILE__</span>),"</font>】//<font color='green'>实际执行代码</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span //</span><span echo 'basename($_SERVER["ORIG_SCRIPT_NAME"]):【',basename($_SERVER['ORIG_SCRIPT_NAME']),"】//如果PHP通过CGI来运行,这个变量的值就是/Php/Php.exe 如果Apache将PHP脚本作为模块来运行,该变量的值应该是/Phptest.php","<br/>";</span>
<span echo</span> "<br/>"<span ;
</span><span echo</span> 'dirname($_SERVER["PHP_SELF"]):【<font color="#EE00EE">',<span dirname</span>(<span $_SERVER</span>['PHP_SELF']),"</font>】//<font color='green'>请求执行文件的</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span echo</span> 'dirname($_SERVER["SCRIPT_NAME"]):【',<span dirname</span>(<span $_SERVER</span>['SCRIPT_NAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span echo</span> 'dirname($_SERVER["SCRIPT_FILENAME"]):【',<span dirname</span>(<span $_SERVER</span>['SCRIPT_FILENAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span echo</span> 'dirname(__FILE__):【<font color="#EE00EE">',<span dirname</span>(<span __FILE__</span>),"</font>】//<font color='green'>实际执行代码</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span //</span><span echo 'dirname($_SERVER["ORIG_SCRIPT_NAME"]):【',dirname($_SERVER['ORIG_SCRIPT_NAME']),"】//如果PHP通过CGI来运行,这个变量的值就是/Php/Php.exe 如果Apache将PHP脚本作为模块来运行,该变量的值应该是/Phptest.php","<br/>";</span>
<span echo</span> "<br/>"<span ;
</span><span echo</span> "require_once "<span ;
</span><span require_once</span>("b/b.php");
<?<span php
</span><span echo</span> "/a/b/b.php<hr/>"<span ;
</span><span echo</span> '$_SERVER["HTTP_HOST"]:【',<span $_SERVER</span>['HTTP_HOST'],"】//当前请求的 Host:即域名信信息","<br/>"<span ;
</span><span echo</span> '<br/>'<span ;
</span><span echo</span> '$_SERVER["PHP_SELF"]:【<font color="#EE00EE">',<span $_SERVER</span>['PHP_SELF'],"</font>】//<font color='green'>请求执行文件的</font><font color='red'>相对</font><font color='blue'>地址</font>","<br/>"<span ;
</span><span echo</span> '$_SERVER["SCRIPT_NAME"]:【',<span $_SERVER</span>['SCRIPT_NAME'],"】//<font color='green'>实际执行文件</font><font color='red'>相对</font><font color='blue'>地址</font>","<br/>"<span ;
</span><span echo</span> '$_SERVER["SCRIPT_FILENAME"]:【',<span $_SERVER</span>['SCRIPT_FILENAME'],"】//<font color='green'>实际执行文件的</font><font color='red'>绝对</font><font color='blue'>路径</font>。","<br/>"<span ;
</span><span echo</span> '__FILE__ :【<font color="#EE00EE">',<span __FILE__</span> ,"</font>】//<font color='green'>实际执行代码的</font><font color='red'>绝对</font><font color='blue'>路径</font>。","<br/>"<span ;
</span><span echo</span> '<br/>'<span ;
</span><span echo</span> '$_SERVER["REQUEST_URI"]:【',<span $_SERVER</span>['REQUEST_URI'],"】//url请求中包括/和之后的所有内容。","<br/>"<span ;
</span><span echo</span> '$_SERVER["QUERY_STRING"]:【',<span $_SERVER</span>['QUERY_STRING'],"】//url请求中?之后的内容。","<br/>"<span ;
</span><span echo</span> '<br/>'<span ;
</span><span echo</span> '$_SERVER["DOCUMENT_ROOT"]:【',<span $_SERVER</span>['DOCUMENT_ROOT'],"】//文档根目录。在服务器配置文件中定义","<br/>"<span ;
</span><span echo</span> "<br/>"<span ;
</span><span echo</span> 'basename($_SERVER["PHP_SELF"]):【<font color="#EE00EE">',<span basename</span>(<span $_SERVER</span>['PHP_SELF']),"</font>】//<font color='green'>请求执行文件的</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span echo</span> 'basename($_SERVER["SCRIPT_NAME"]):【',<span basename</span>(<span $_SERVER</span>['SCRIPT_NAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span echo</span> 'basename($_SERVER["SCRIPT_FILENAME"]):【',<span basename</span>(<span $_SERVER</span>['SCRIPT_FILENAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span echo</span> 'basename(__FILE__):【<font color="#EE00EE">',<span basename</span>(<span __FILE__</span>),"</font>】//<font color='green'>实际执行代码</font>的<font color='blue'>文件名</font>","<br/>"<span ;
</span><span //</span><span echo 'basename($_SERVER["ORIG_SCRIPT_NAME"]):【',basename($_SERVER['ORIG_SCRIPT_NAME']),"】//如果PHP通过CGI来运行,这个变量的值就是/Php/Php.exe 如果Apache将PHP脚本作为模块来运行,该变量的值应该是/Phptest.php","<br/>";</span>
<span echo</span> "<br/>"<span ;
</span><span echo</span> 'dirname($_SERVER["PHP_SELF"]):【<font color="#EE00EE">',<span dirname</span>(<span $_SERVER</span>['PHP_SELF']),"</font>】//<font color='green'>请求执行文件的</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span echo</span> 'dirname($_SERVER["SCRIPT_NAME"]):【',<span dirname</span>(<span $_SERVER</span>['SCRIPT_NAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span echo</span> 'dirname($_SERVER["SCRIPT_FILENAME"]):【',<span dirname</span>(<span $_SERVER</span>['SCRIPT_FILENAME']),"】//<font color='green'>实际执行文件</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span echo</span> 'dirname(__FILE__):【<font color="#EE00EE">',<span dirname</span>(<span __FILE__</span>),"</font>】//<font color='green'>实际执行代码</font>的<font color='blue'>所在目录</font>","<br/>"<span ;
</span><span //</span><span echo 'dirname($_SERVER["ORIG_SCRIPT_NAME"]):【',dirname($_SERVER['ORIG_SCRIPT_NAME']),"】//如果PHP通过CGI来运行,这个变量的值就是/Php/Php.exe 如果Apache将PHP脚本作为模块来运行,该变量的值应该是/Phptest.php","<br/>";</span>
<span echo</span> "<br/>";