I have an include that references $PHP_SELF. This script it wasn't working as expected on certain pages, and I discovered that these pages all called the include with an absolute URL, like so: include("http://blabla/include.php")
In these cases, $PHP_SELF was equal to include.php. When a relative URL is used [ include("../include.php") ], $PHP_SELF is equal to the script that calls the include.
It's no hassle to change the few pages which use an absolute URL, but I'm curious as to why this happens. Can anyone explain?
Thanks.
Absolute and relative includes
Moderator: General Moderators
-
I have trouble with that all day. Each server returns different values for php_self, document_root or script_name.
Would like to hear a solution that fits all servers also.
Currently I have a class that checks all of them and combines them to what I need, including adding missing slashes or removing slashes and so on.
It really get's funny when you have a url, with differnt path than the document_root, which also is different from the users_root :)
djot
-
I have trouble with that all day. Each server returns different values for php_self, document_root or script_name.
Would like to hear a solution that fits all servers also.
Currently I have a class that checks all of them and combines them to what I need, including adding missing slashes or removing slashes and so on.
It really get's funny when you have a url, with differnt path than the document_root, which also is different from the users_root :)
djot
-
actually, it's quite simple....
if you include on the same server, that text (or code) is handled by the current instance of the php-engine -> $_SERVER['PHP_SELF'] has the value of the script that is requested by the user
if you include through url, php requests apache the _output_ of the script -> a new php-engine instance is initialised to execute the code (explains the different $_SERVER['PHP_SELF'] value), and then the output is returned to apache -> and to the requesting script...
if you include on the same server, that text (or code) is handled by the current instance of the php-engine -> $_SERVER['PHP_SELF'] has the value of the script that is requested by the user
if you include through url, php requests apache the _output_ of the script -> a new php-engine instance is initialised to execute the code (explains the different $_SERVER['PHP_SELF'] value), and then the output is returned to apache -> and to the requesting script...