The difference between $_server[php_self] and $_server[script_name in PHP _php skill

Source: Internet
Author: User
"Php_self"
The name of the file that is currently executing the script, 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/test.php/foo.bar this result. The __FILE__ constant contains the absolute path and file name of the current (for example, included) 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, include files).

The main reasons for such as: $_server[' php_self ']? $_server[' php_self ']: $_server[' script_name '];

The reasons for finding better are:
Today, installing a PHP program on the DreamHost found that the connection address will be a cgi-system, but the program config is not a problem, check the data to find out is script_name and php_self different problems caused.
It's usually not $_server[' script_name ' with $_server[' php_self ' in this test, because most PHP is not run in CGI mode.
But PHP on the DreamHost is running in CGI, and there is a distinct difference.
echo $_server[' Script_name ']; (/cgi-system/php.cgi)
echo $_server[' php_self ']; (/admin/test.php)

A note was found from http://lists.nyphp.org/pipermail/talk/2005-July/015339.html. Said the foreigner.

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 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 this is undefined, so
Even if it works in the current browsers, it might not work in future ones

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.