Rumah > Artikel > pembangunan bahagian belakang > php应用路径变量问题总结_PHP教程
本地服务器,域名http://d.com,根路径D:\phpnow\vhosts\d.com.yii,相对根目录拥有文件/x.php代码里requeir_once /a/a.php,而/a/a.php又requeir_once /a/b/b.php
/x.php
$_SERVER["HTTP_HOST"]:【d.com】//当前请求的 Host:即域名信信息
$_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】//url请求中包括/和之后的所有内容。
$_SERVER["QUERY_STRING"]:【a=b&c=d】//url请求中?之后的内容。
$_SERVER["DOCUMENT_ROOT"]:【D:/phpnow/vhosts/d.com.yii】//文档根目录。在服务器配置文件中定义
basename($_SERVER["PHP_SELF"]):【】//的
basename($_SERVER["SCRIPT_NAME"]):【x.php】//的
basename($_SERVER["SCRIPT_FILENAME"]):【x.php】//的
basename(__FILE__):【】//的
dirname($_SERVER["PHP_SELF"]):【】//的
dirname($_SERVER["SCRIPT_NAME"]):【\】//的
dirname($_SERVER["SCRIPT_FILENAME"]):【D:/phpnow/vhosts/d.com.yii】//的
dirname(__FILE__):【】//的
require_once /a/a.php
$_SERVER["HTTP_HOST"]:【d.com】//当前请求的 Host:即域名信信息
$_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】//url请求中包括/和之后的所有内容。
$_SERVER["QUERY_STRING"]:【a=b&c=d】//url请求中?之后的内容。
$_SERVER["DOCUMENT_ROOT"]:【D:/phpnow/vhosts/d.com.yii】//文档根目录。在服务器配置文件中定义
basename($_SERVER["PHP_SELF"]):【】//的
basename($_SERVER["SCRIPT_NAME"]):【x.php】//的
basename($_SERVER["SCRIPT_FILENAME"]):【x.php】//的
basename(__FILE__):【】//的
dirname($_SERVER["PHP_SELF"]):【】//的
dirname($_SERVER["SCRIPT_NAME"]):【\】//的
dirname($_SERVER["SCRIPT_FILENAME"]):【D:/phpnow/vhosts/d.com.yii】//的
dirname(__FILE__):【】//的
require_once /a/b/b.php
$_SERVER["HTTP_HOST"]:【d.com】//当前请求的 Host:即域名信信息
$_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】//url请求中包括/和之后的所有内容。
$_SERVER["QUERY_STRING"]:【a=b&c=d】//url请求中?之后的内容。
$_SERVER["DOCUMENT_ROOT"]:【D:/phpnow/vhosts/d.com.yii】//文档根目录。在服务器配置文件中定义
basename($_SERVER["PHP_SELF"]):【】//的
basename($_SERVER["SCRIPT_NAME"]):【x.php】//的
basename($_SERVER["SCRIPT_FILENAME"]):【x.php】//的
basename(__FILE__):【】//的
dirname($_SERVER["PHP_SELF"]):【】//的
dirname($_SERVER["SCRIPT_NAME"]):【\】//的
dirname($_SERVER["SCRIPT_FILENAME"]):【D:/phpnow/vhosts/d.com.yii】//的
dirname(__FILE__):【】//的
/a/a.php
$_SERVER["HTTP_HOST"]:【d.com】//当前请求的 Host:即域名信信息
$_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】//url请求中包括/和之后的所有内容。
$_SERVER["QUERY_STRING"]:【a=b&c=d】//url请求中?之后的内容。
$_SERVER["DOCUMENT_ROOT"]:【D:/phpnow/vhosts/d.com.yii】//文档根目录。在服务器配置文件中定义
basename($_SERVER["PHP_SELF"]):【】//的
basename($_SERVER["SCRIPT_NAME"]):【a.php】//的
basename($_SERVER["SCRIPT_FILENAME"]):【a.php】//的
basename(__FILE__):【】//的
dirname($_SERVER["PHP_SELF"]):【】//的
dirname($_SERVER["SCRIPT_NAME"]):【/a】//的
dirname($_SERVER["SCRIPT_FILENAME"]):【D:/phpnow/vhosts/d.com.yii/a】//的
dirname(__FILE__):【】//的
require_once /a/b/b.php
$_SERVER["HTTP_HOST"]:【d.com】//当前请求的 Host:即域名信信息
$_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】//url请求中包括/和之后的所有内容。
$_SERVER["QUERY_STRING"]:【a=b&c=d】//url请求中?之后的内容。
$_SERVER["DOCUMENT_ROOT"]:【D:/phpnow/vhosts/d.com.yii】//文档根目录。在服务器配置文件中定义
basename($_SERVER["PHP_SELF"]):【】//的
basename($_SERVER["SCRIPT_NAME"]):【a.php】//的
basename($_SERVER["SCRIPT_FILENAME"]):【a.php】//的
basename(__FILE__):【】//的
dirname($_SERVER["PHP_SELF"]):【】//的
dirname($_SERVER["SCRIPT_NAME"]):【/a】//的
dirname($_SERVER["SCRIPT_FILENAME"]):【D:/phpnow/vhosts/d.com.yii/a】//的
dirname(__FILE__):【】//的
/x.php
<?<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");
/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");
/a/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/>";