"PHP_SELF"
The file name of the currently executing script, related to the document root. For example, using $_SERVER['PHP_SELF'] in a script with the URL address http://www.jb51.net/test.php/foo.bar will result in /test.php/foo.bar. The __FILE__ constant contains the absolute path and file name of the current (i.e. containing) file.
"SCRIPT_NAME"
Contains the path to the current script. This is useful when the page needs to point to itself. __FILE__ contains the absolute path and file name of the current file (such as an include file).
The main reasons are like: $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
The better reasons are:
When installing a PHP program on Dreamhost today It was found that the connected address would have an extra cgi-system, but there was no problem with the program's config. After checking the information, I found that the problem was caused by the difference between SCRIPT_NAME and PHP_SELF.
Usually testing $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF'] on this machine probably won't see any difference, because most PHP does not run in CGI mode.
But PHP on DreamHost runs in CGI mode, so there are obvious differences between the two.
echo $_SERVER['SCRIPT_NAME']; // (/cgi-system/php.cgi)
echo $_SERVER['PHP_SELF']; // (/admin/test.php)
From http://lists. A note was found at nyphp.org/pipermail/talk/2005-July/015339.html. Said by foreigners.
SCRIPT_NAME solves all the problems mentioned
in this thread - it's just the script name, without any extra garbage
that might be tacked on by the user. PHP_SELF explicitly includes that
extra garbage, so solutions in this thread that involve stripping the
garbage off of PHP_SELF to make it safe are really, really missing the
point - just use SCRIPT_NAME instead. Please don't use FORM ACTION="";
according to the spec, what the browser does with that is undefined, so
even if it works in current browsers, it might not work in future ones
The above introduces the difference between $_SERVER[PHP_SELF] and $_SERVER[SCRIPT_NAME] in windows 2003 server php, including the content of windows 2003 server. I hope it will be helpful to friends who are interested in PHP tutorials.