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

Source: Internet
Author: User
Tags website hosting

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.

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

Related Article

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.