Differences between $ _ SERVER [PHP_SELF] and $ _ SERVER [SCRIPT_NAME] in php _ PHP Tutorial

Source: Internet
Author: User
Tags website hosting
The difference between $ _ SERVER [PHP_SELF] and $ _ SERVER [SCRIPT_NAME] in php. "PHP_SELF" indicates the file name of the script being executed, which is related to documentroot. For example, use $ _ SERVER [P "PHP_SELF" in the script with the URL address www. jb51.nettest. phpfoo. bar"
The file name of the script being executed, 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 get the result of/test. PHP/foo. bar. The _ FILE _ constant contains the absolute path and FILE name of the current (such as include) FILE.

"SCRIPT_NAME"
The path that contains 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, including the FILE ).

The main reasons are as follows: $ _ SERVER ['php _ SELF ']? $ _ SERVER ['php _ SELF ']: $ _ SERVER ['script _ name'];

The better reason is:
Today, when I installed a set of PHP programs on the Dreamhost, I found that there would be an additional cgi-system address, but the config of the program has no problem, after checking the information, we found the problem caused by different SCRIPT_NAME and PHP_SELF.
Generally, the website hosting $ _ SERVER ['script _ name'] and $ _ SERVER ['php _ SELF '] on the current machine cannot be seen as different, because most PHP does not run in CGI mode.
However, PHP on DreamHost runs in CGI mode, and there are obvious differences between the two.
Echo $ _ SERVER ['script _ name']; // (/cgi-system/php. cgi)
Echo $ _ SERVER ['php _ SELF ']; // (/admin/test. PHP)

Found a description from the http://lists.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 provided des that
Extra garbage, so solutions in this thread that involve stripping
Garbage off of PHP_SELF to make it safe are really, really missing
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 file name of the script being executed. it is related to document root. For example, use $ _ SERVER ['p...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.