TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Ask about 2 Predefined Variables (http://www.talkphp.com/absolute-beginners/3693-ask-about-2-predefined-variables.html)

superthin 12-02-2008 02:33 AM

Ask about 2 Predefined Variables
 
Hello all,

Please tell me the difference of $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF']. I read PHP Docs from php.net but I cannot understand.

If both is the same, which should I use for better performance?

Thanks a lot!

zxt3st 12-02-2008 07:15 AM

$_SERVER['PHP_SELF']

This is the filename of the currently executing script, relative to the document root. However, unlike $_SERVER['SCRIPT_NAME'], it provides additional path information like $_SERVER['REQUEST_URI'] when the actual php file is present in the path. So when the $_SERVER['REQUEST_URI'] is /index.php/big/directory/ then $_SERVER['PHP_SELF'] will be
Code:

/index.php/big/directory/.
However if all the URI's under http://www.example.com/ is mapped to http://www.example.com/index.php, then, for example, http://www.example.com/abc/def will return
Code:

/index.php
like $_SERVER['SCRIPT_NAME']. Note that $_SERVER['REQUEST_URI'] data is ignored for this request.

Further References:
Understanding $_SERVER['PHP_SELF'], $PHP_SELF, $_SERVER['REQUEST_URI'] and $_SERVER['SCRIPT_NAME'] in PHP and when to use what

Wildhoney 12-02-2008 08:09 PM

I often get confused as to which I should be using. It would be nice to have a better solution -- if that is possible.

zxt3st 12-02-2008 11:06 PM

yes i agree on that wildhoney, i also got confuse on what really to use as best, but i think there is no such thing like that :)


All times are GMT. The time now is 08:15 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0