By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,497 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,497 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Thanks!

Sincerely,
-Josh
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Joshua Beall" <jb****@donotspam.remove.me.heraldic.us> wrote in message
news:Eq1rd.2268$M57.2218@trnddc01...
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?

Thanks!

Sincerely,
-Josh


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.
Jul 17 '05 #2

P: n/a
Chung Leong wrote:
PHP_SELF is apparently SCRIPT_NAME + PATH_INFO.
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.
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.


Right.

--
Jock
Jul 17 '05 #3

P: n/a

"John Dunlop" <us*********@john.dunlop.name> wrote in message
news:MP************************@News.Individual.NE T...
Chung Leong wrote:
PHP_SELF is apparently SCRIPT_NAME + PATH_INFO.


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.
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.


Right.

--
Jock


Well, the info I provided was from experimentation.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.