The difference between $_server[php_self] and $_server[script_name] in PHP "Php_self" is currently executing the file name of the script, which is related to document root. For example, using $_server[' php_self ' in a script with a URL address of Http://www.jb51.net/test.php/foo.bar will give the result/test.php/foo.bar. The __FILE__ constant contains the absolute path and file name of the current (for example, the 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 (for example, include files).
The main reasons are like: $_server[' php_self ']? $_server[' php_self ': $_server[' script_name '];
the reasons for finding better are: when I installed a PHP program on DreamHost Today, I found that the connected address would have an extra cgi-system, but the program's config did not have a problem, and the information was found to be the result of script_name and php_self different problems. usually in the test $_server[' script_name ' and $_server[' php_self '] probably don't see any difference, because most of PHP is not running in CGI mode. but the PHP on the DreamHost is run in CGI, and the difference between the two is obvious. echo $_server[' script_name ';//(/CGI-SYSTEM/PHP.CGI) echo $_server[' php_self ';//(/admin/test.php)
a description was found from http://lists.nyphp.org/pipermail/talk/2005-July/015339.html. The foreigner said.
Script_name solves all the problems mentioned in this thread-it ' s just the script name, without any extra garbage That might is tacked on by the user. Php_self explicitly includes that extra garbage, so solutions on this thread that involve stripping the garbage off of php_self to make it safe is really, really missing the point-just use Script_name instead. Please don ' t use FORM action= ""; according to the spec, what's the browser does with that's undefined, so even if it works in the current browsers, it might don't work in the future ones
The difference between $_server[php_self] and $_server[script_name] in PHP