首頁  >  文章  >  後端開發  >  php应用路径变量问题总结_PHP教程

php应用路径变量问题总结_PHP教程

WBOY
WBOY原創
2016-07-20 11:15:03806瀏覽

本地服务器,域名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/>";

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440233.htmlTechArticle本地服务器,域名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...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn