$_SERVER['DOCUMENT_ROOT'] 值为空,但是在phpinfo()测试页面中却有实际数据,这是我的程序哪里有问题?还是配置上的问题啊?
/*
测试程序
调用Base_Info.php
*/
print_r($_SERVER);
$SYSTEM_ROOT_PATH = $_SERVER['DOCUMENT_ROOT'];
#echo $_SERVER['DOCUMENT_ROOT']."\n";
echo $SYSTEM_ROOT_PATH;
/*
include("$SYSTEM_ROOT_PATH\Lib\Base_Info.php");
$class = new Base_Info();
$S_Info = $class->System_Info();
foreach ($key as $value){
echo "$key========$value"."\n";
}
*/
$_SERVER数组输出
[ALLUSERSPROFILE] => C:\ProgramData
[ANT_HOME] => D:\hadoop\apache-ant-1.9.2
[APPDATA] => C:\Users\yjn\AppData\Roaming
[CLASSPATH] => ,;D:\hadoop\Java/lib/dt.jar;D:\hadoop\Java/lib/tools.jar
[CommonProgramFiles] => C:\Program Files (x86)\Common Files
[CommonProgramFiles(x86)] => C:\Program Files (x86)\Common Files
[CommonProgramW6432] => C:\Program Files\Common Files
[COMPUTERNAME] => YJN-PC
[ComSpec] => C:\Windows\system32\cmd.exe
[FP_NO_HOST_CHECK] => NO
[HOMEDRIVE] => C:
[HOMEPATH] => \Users\yjn
[JAVA_HOME] => D:\hadoop\Java
[LOCALAPPDATA] => C:\Users\yjn\AppData\Local
[LOGONSERVER] => \\YJN-PC
[NUMBER_OF_PROCESSORS] => 2
[OS] => Windows_NT
[Path] => C:\Perl64\site\bin;C:\Perl64\bin;C:\Windows\system32;C:\Windows;
ndows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\hadoop\J
in;D:\hadoop\Java/jre/bin;D:\hadoop\apache-ant-1.9.2\bin;D:\php5;D:\php5\ex
[PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
[PROCESSOR_ARCHITECTURE] => x86
[PROCESSOR_ARCHITEW6432] => AMD64
[PROCESSOR_IDENTIFIER] => Intel64 Family 6 Model 23 Stepping 10, GenuineIn
[PROCESSOR_LEVEL] => 6
[PROCESSOR_REVISION] => 170a
[ProgramData] => C:\ProgramData
[ProgramFiles] => C:\Program Files (x86)
[ProgramFiles(x86)] => C:\Program Files (x86)
[ProgramW6432] => C:\Program Files
[PROMPT] => $P$G
[PSModulePath] => C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
[PUBLIC] => C:\Users\Public
[SESSIONNAME] => Console
[SystemDrive] => C:
[SystemRoot] => C:\Windows
[TEMP] => C:\Users\yjn\AppData\Local\Temp
[TMP] => C:\Users\yjn\AppData\Local\Temp
[USERDOMAIN] => yjn-PC
[USERNAME] => yjn
[USERPROFILE] => C:\Users\yjn
[windir] => C:\Windows
[windows_tracing_flags] => 3
[windows_tracing_logfile] => C:\BVTBin\Tests\installpackage\csilogfile.log
[PHP_SELF] => test.php
[SCRIPT_NAME] => test.php
[SCRIPT_FILENAME] => test.php
[PATH_TRANSLATED] => test.php
[DOCUMENT_ROOT] =>
[REQUEST_TIME] => 1381282125
[argv] => Array
(
[0] => test.php
)
[argc] => 1
$_SERVER['DOCUMENT_ROOT'] 需要在服务器配置中指定,你确认phpinfo有这个值么?
你$_SERVER数组输出['DOCUMENT_ROOT']很明显是空的
确实在phpinfo中能到得到该值。很奇怪,不知道代码中是否有问题
httpd.conf中的设置
DocumentRoot "D:\Apache\htdocs"
_SERVER["DOCUMENT_ROOT"] D:/Apache/htdocs
你$_SERVER数组输出['DOCUMENT_ROOT']很明显是空的
我就想知道为什么是空?
echo $_SERVER["DOCUMENT_ROOT"];
个人觉得不应该纠结于 $_SERVER['DOCUMENT_ROOT']
这个变量并不是通行于各个服务器,说不准换了一台服务器就要查错并重写代码了
建议用 __FILE__ 或 __DIR__
如果确实需要知道所以然,就去查资料吧,据闻虚拟机用这个变量也是有问题,没有环境实测