Difference between $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF']

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi All,

What is the difference between $_SERVER['SCRIPT_NAME'] and
$_SERVER['PHP_SELF'], and which is better to use?

According to the CGI 1.1 spec (http://hoohoo.ncsa.uiuc.edu/cgi/env.html ),
SCRIPT_NAME is not something specific to Apache (if I understand that
correctly).  But where does PHP_SELF come from?  What creates that?
According to http://php.net/reserved.variables , PHP has no control over the
$_SERVER array.  Quote:

"The entries in this array are created by the webserver. There is no
guarantee that every webserver will provide any of these; servers may omit
some, or provide others not listed here. That said, a large number of these
variables are accounted for in the CGI 1.1 specification, so you should be
able to expect those."

So, of those two, should I be concerned about one being less portable than
the other, or that one might change in the future?



Re: Difference between $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF']

Quoted text here. Click to load it

Good question. PHP_SELF is apparently SCRIPT_NAME + PATH_INFO. If the URL is
http://www.example.net/index.php/hello/world , PHP_SELF is
/index.php/hello/world while SCRIPT_NAME is just /index.php.

Re: Difference between $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF']

Chung Leong wrote:

Quoted text here. Click to load it

PHP_SELF has nothing to do with script names, file names,
directories or the organisation of the server; so far as I
can see, it's the path component of the URI.  The Manual is
wrong here.  Also, its description of SCRIPT_NAME, though
vague, is almost passable.

Quoted text here. Click to load it



Re: Difference between $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF']

Quoted text here. Click to load it

Well, the info I provided was from experimentation.

Site Timeline