“PHPSELF” @H502_0@当前正在执行脚本的文件名,与 document root 相关。举例来说,在 URL 地址为 //www.jb51.cc/test.PHP/foo.bar 的脚本中使用 $_SERVER['PHP_SELF'] 将会得到 /test.PHP/foo.bar 这个结果。FILE 常量包含当前(例如包含)文件的绝对路径和文件名。 “SCRIPTNAME” @H502_0@包含当前脚本的路径。这在页面需要指向自己时非常有用。FILE 包含当前文件的绝对路径和文件名(例如包含文件)。 主要的原因如像:$_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPTNAME']; 找到更好的原因是: @H502_0@今天在Dreamhost上安裝一套PHP程序時發現連接的地址都會多出一個cgi-system來,但是程序的config並沒有問題,查了查資料才發現是SCRIPT_NAME和PHPSELF不同造成的問題。 @H502_0@通常在本機測試 $_SERVER['SCRIPT_NAME'] 跟 $_SERVER['PHP_SELF'] 大概看不出有什麼不同,因為大部分的PHP不是以CGI模式運行的。 @H_502_0@但 DreamHost 上的 PHP 是以 CGI 方式運行,二者就有明顯不同的差異。 @H_502_0@echo $_SERVER['SCRIPT_NAME']; // (/cgi-system/PHP.cgi) @H_502_0@echo $_SERVER['PHP_SELF']; // (/admin/test.PHP) 从http://lists.nyPHP.org/pipermail/talk/2005-July/015339.html 发现了一个说明。老外说的。 SCRIPTNAME solves all the problems mentioned @H5020@in this thread - it's just the script name,without any extra garbage @H502_0@that might be tacked on by the user. PHPSELF explicitly includes that @H5020@extra garbage,so solutions in this thread that involve stripping the @H502_0@garbage off of PHPSELF to make it safe are really,really missing the @H502_0@point - just use SCRIPTNAME instead. Please don't use FORM ACTION=”"; @H5020@according to the spec,what the browser does with that is undefined,so @H502_0@even if it works in current browsers,it might not work in future ones