Why use $mosconfig_absolute_path?

For Joomla! 1.0 Coding related discussions.
Locked
camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Why use $mosconfig_absolute_path?

Post by camos » Sat Mar 25, 2006 3:22 am

This is not much of an issue but I am curious to know why Joomla needs to use $mosconfig_absolute_path?  It seems an unnecessary redundancy since everything in a site is relative to the domain document root handled by $mosconfig_live_site.

Apart from the redundancy the only advantage to getting rid of the absolute path is a simplified transport from one server to another without having to figure out what the absolute path actually is.

Cheers

Oops stuck this in the wrong place.  Oh well, where is that coffee?
Last edited by camos on Sat Mar 25, 2006 3:25 am, edited 1 time in total.
Freedom is not free!
It is however Open Source.

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Mon Apr 03, 2006 2:57 am

I guess no one knows and no one cares.

How disappointing.
Freedom is not free!
It is however Open Source.

User avatar
nibra
Joomla! Guru
Joomla! Guru
Posts: 588
Joined: Wed Nov 16, 2005 2:02 am
Location: Breklum - Nordfriesland
Contact:

Re: Why use $mosconfig_absolute_path?

Post by nibra » Mon Apr 03, 2006 3:45 am

camos wrote: This is not much of an issue but I am curious to know why Joomla needs to use $mosconfig_absolute_path?  It seems an unnecessary redundancy since everything in a site is relative to the domain document root handled by $mosconfig_live_site.
It is very useful when dealing with multisites. It prevents problems with nested inclusions. I'm glad to have it.
camos wrote: I guess no one knows and no one cares.
You're too impatient. Half an hour is no time on forums.

Regards
Niels

User avatar
kenmcd
Joomla! Champion
Joomla! Champion
Posts: 5672
Joined: Thu Aug 18, 2005 2:09 am
Location: California
Contact:

Re: Why use $mosconfig_absolute_path?

Post by kenmcd » Mon Apr 03, 2006 3:48 am

Joomla needs it for all file operations.
Search Joomla 1.0.8 for $mosconfig_absolute_path
Searched 1557 file(s), found 262 occurrences in 71 file(s)

3PD components need it for all file operations.
Search DOCMan 1.3-RC-2 for $mosconfig_absolute_path
Searched 244 file(s), found 64 occurrences in 20 file(s)


When Joomla is working with files it is using the server file system, not a web server URL.
Thus it needs to know where it is located within that file system - the absolute path.
██ LibreTraining

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Mon Apr 03, 2006 4:50 am

nibra wrote:
camos wrote: This is not much of an issue but I am curious to know why Joomla needs to use $mosconfig_absolute_path?  It seems an unnecessary redundancy since everything in a site is relative to the domain document root handled by $mosconfig_live_site.
It is very useful when dealing with multisites. It prevents problems with nested inclusions. I'm glad to have it.
camos wrote: I guess no one knows and no one cares.
You're too impatient. Half an hour is no time on forums.
Thanks, that is the kind of info I was looking for.  I find the absolute path to be a PITA but just because I could not see any reason for using it does not mean there is no justification. 

Don't just look at the hours, look at the days as well.

Cheers
Freedom is not free!
It is however Open Source.

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Mon Apr 03, 2006 5:04 am

kenmcd wrote:
Joomla needs it for all file operations.
Search Joomla 1.0.8 for $mosconfig_absolute_path
Searched 1557 file(s), found 262 occurrences in 71 file(s)

3PD components need it for all file operations.
Search DOCMan 1.3-RC-2 for $mosconfig_absolute_path
Searched 244 file(s), found 64 occurrences in 20 file(s)


When Joomla is working with files it is using the server file system, not a web server URL.
Thus it needs to know where it is located within that file system - the absolute path.
I don't understand this point.  Just because absolute_path is being used does not mean it is necessary.  It could be used just because it was there.  A file in the system is not much different from a file in a Website however it may be easier to count/sort them when using the system rather than the Webserver. Perhaps the reason is something like that.  A relative url is just as precise in locating a file as the absolute path.  A relative url may even be more accurate if the Webserver uses symlinks to different harddrives to extend the Webspace.  What would Joomla or DocMan do about an absolute_path if half the files were on one HD and half were on another?

Cheers
Freedom is not free!
It is however Open Source.

User avatar
kenmcd
Joomla! Champion
Joomla! Champion
Posts: 5672
Joined: Thu Aug 18, 2005 2:09 am
Location: California
Contact:

Re: Why use $mosconfig_absolute_path?

Post by kenmcd » Mon Apr 03, 2006 5:21 am

kenmcd wrote: When Joomla is working with files it is using the server file system, not a web server URL.
Thus it needs to know where it is located within that file system - the absolute path.
You are confusing a relative URL and a file path.

Web servers talk to browsers via URLs.
Applications talk to the server via the file system, paths
Joomla is an application which communicates with the server via the file system.

When you install applications on your computer, do they save URLs in the configuration (the registry), or do they save the file paths?
Obviously the file paths are saved in the Windows registry.
Same on Linux - file paths.
██ LibreTraining

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Mon Apr 03, 2006 6:18 am

I admit I don't know how Joomla does its thing.  Perhaps using an absolute path rather than an URL whether it is relative or absolute is necessary in some cases.  It seems to me though, comparing the files on a Webserver directly to the files system in use on an OS is not relevant because if it was then it would not be too likely that Joomla would run on both Linux Apache and Windows IIS servers.  The OS does the interpreting of the file system it uses and delivers the result to the Webserver which does its own interpretaion before delivering the result to the Webserver.... or something like that.

Is there something specific in Joomla that is known to require an absolute path?

Cheers
Freedom is not free!
It is however Open Source.

User avatar
nibra
Joomla! Guru
Joomla! Guru
Posts: 588
Joined: Wed Nov 16, 2005 2:02 am
Location: Breklum - Nordfriesland
Contact:

Re: Why use $mosconfig_absolute_path?

Post by nibra » Mon Apr 03, 2006 6:50 am

camos wrote: Is there something specific in Joomla that is known to require an absolute path?
Not really, it is a common necessity for a script to access the filesystem of the machine, it is running on (absolute path), as it is for a browser to know, where to get resources from (live_site).

Regards
Niels

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Mon Apr 03, 2006 6:56 am

I guess using an absolute path would make running a script easier to handle but it generally is not necessary for the path to be absolute.  Scripts run from the dir they are in and any relative paths in the script must take into account starting from that dir.  If the script was put into another dir then the relative path would also be different and would add a complication.  I think though that a relative or absolute URL would also suffice just as well, like when running a script from the section of a template.

Cheers
Freedom is not free!
It is however Open Source.

Narcissus
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 109
Joined: Wed Sep 07, 2005 5:02 pm

Re: Why use $mosconfig_absolute_path?

Post by Narcissus » Mon Apr 03, 2006 7:33 am

camos:

As nibra mentioned, nested includes screws up when using relative paths.

As an example, imagine this really poorly drawn directory structure:
      DIR_A: fileA
          : fileB
          : DIR_A_B: fileAB
                    : fileB
                    : DIR_A_B_C: fileABC


If fileAB includes '../fileB' and fileABC includes '../fileAB' then fileABC will actually end up including fileB from the DIR_A_B directory, even though the included fileAB references the fileB in DIR_A.

This is because the include effectively copies the code directly in to the file. Once it's there, the include of '../fileB' references the subdirectory DIR_A_B.

Hence, including files with relative paths is a bad idea, as then you can't just include files all across the code base.

Lincoln.

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Mon Apr 03, 2006 5:09 pm

Relative paths are just as specific as absolute paths and do not collect everything on route.  File systems, even Windows, can use relative paths just as Webservers use relative URLs.  Using a / at the beginning makes the path relative to the Webroot so /includes/file.php will alway be found no matter where it is called from.  In order to make Joomla easily transportable the live_site variable can be used to make a relative url absolute so it automatically becomes http://mydomain.com/includes/file.php or http://mydomain.com/joomla/includes/file.php if Joomla is installed in a subdir off the root.

After re-reading one of Ken's posts It occured to me one possible reason for an absolute file path might be that the CHMOD utility in the backend requires it.  That utility however came long after the use of absolute_path was well entrenched in the Mambo code.  CHMOD does not work with Windows servers and it will not change the file permissions even though, for example, configuration.php does somehow become unwritable by Joomla when the box is checked.  I have not checked to see if that is also the case on a *nix server.

PHP scripting was developed specifically for use on Webservers, in fact the name was at first an acronym for Personal Home Page before it became Pre Hypertext Processor or just Hypertext Preprocessor.  It is highly unlikely there is anything in PHP that requires an absolute file path but I guess that could change depending on how the script is written. The absolute path variable seems to be another poorly though out legacy just like the menu ID, page types and section/categories are. 

Cheers
Freedom is not free!
It is however Open Source.

User avatar
nibra
Joomla! Guru
Joomla! Guru
Posts: 588
Joined: Wed Nov 16, 2005 2:02 am
Location: Breklum - Nordfriesland
Contact:

Re: Why use $mosconfig_absolute_path?

Post by nibra » Mon Apr 03, 2006 5:34 pm

camos wrote: It is highly unlikely there is anything in PHP that requires an absolute file path but I guess that could change depending on how the script is written. The absolute path variable seems to be another poorly though out legacy just like the menu ID, page types and section/categories are. 
How do you access the configuration.php from a script in myincludes/showconfig.php?

Regards
Niels

Narcissus
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 109
Joined: Wed Sep 07, 2005 5:02 pm

Re: Why use $mosconfig_absolute_path?

Post by Narcissus » Mon Apr 03, 2006 6:02 pm

camos:

I just did this to confirm what I'm saying. At least, this is how it's happening on my version of PHP (4.something). Any chance of you seeing if it happens the same on your computer?

In a subdirectory 'X':
a) create file 'b.php' that just runs print __FILE__;
b) create directory 'ab'
c) copy the 'b.php' file to the new directory
d) in this same directory create 'ab.php' that just runs include( '../b.php');
e) in this directory, create another directory called 'abc'
f) in this new directory, create a file called 'abc.php' that just runs include( '../ab.php');

Now, call this file from within your browser.

If abc.php includes '../ab.php', and the ab.php file just includes '../b.php' you would assume, then, that it would print out the filename of the b.php file one directory up from ab.php (the one in the 'root'), right?

Well, in my PHP installation, it displays the name of the file b.php that is one directory up from abc.php.

That's why you need absolute paths when including.


If you don't feel like doing it, can anyone else run this and confirm or deny it for me please?

Lincoln.

Narcissus
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 109
Joined: Wed Sep 07, 2005 5:02 pm

Re: Why use $mosconfig_absolute_path?

Post by Narcissus » Mon Apr 03, 2006 6:15 pm

Also, I would like to say that (after investigating this at php.net just then) there other people arguing both sides of this, so you may not have the problem.

That is to say, 'Your Mileage May Vary' with this case but definitely some people are experiencing it.

Also, if I include '/includes/file.php' it definitely pulls it from the includes directory at the root of my drive, not my webroot. I don't know if these two 'facts' are related or not...

So, in the interest of making things work on as many machines as possible, definitely I believe the absolute path in live_site is a good idea!

Lincoln.

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Mon Apr 03, 2006 7:47 pm

If abc.php includes b.php from another dir the script is still runing from the dir abc.php is in so the relative path in b.php would be starting from the dir abc.php is in.

The Webroot is the beginning of your Web space and is not necessarily in the root of your HD or the space allocated to your user account.
So, in the interest of making things work on as many machines as possible, definitely I believe the absolute path in live_site is a good idea!
We are discussing the variables $mosConfig_absolute_path which is the file path on the HD space and $mosConfig_live_site which is essentially the Webroot at http://mydomain.com. Assuming no typo in the above statement I don't know what your conclusion means.

The only reason I can think of for using the absolute file path is to directly access a file or dir outside of the Web space which is generally not necessary and is likely not a good idea anyway.  The proper way to do that is by using a virtual dir as is done with cgi-bin.  Only the Webserver should be allowed access outside the Webroot, certainly no script should have that ability in a hosted environment.

Using the live_site variable is essentially the same as using the absolute_path variable and both are quite different from using ../../ to traverse a dir.  It is not always obvious where the Webroot is.  Using this absolute file path /home/virtual/site49/fst/var/www/html, the Webroot could be either /www or /html at the discression of the admin who set up Apache.

Cheers
Freedom is not free!
It is however Open Source.

User avatar
nibra
Joomla! Guru
Joomla! Guru
Posts: 588
Joined: Wed Nov 16, 2005 2:02 am
Location: Breklum - Nordfriesland
Contact:

Re: Why use $mosconfig_absolute_path?

Post by nibra » Mon Apr 03, 2006 8:15 pm

camos wrote: We are discussing the variables $mosConfig_absolute_path which is the file path on the HD space and $mosConfig_live_site which is essentially the Webroot at http://mydomain.com. Assuming no typo in the above statement I don't know what your conclusion means.
There is no inherent relationship between the filesystem, where the files live, and the structure seen via HTTP.
camos wrote: The only reason I can think of for using the absolute file path is to directly access a file or dir outside of the Web space which is generally not necessary and is likely not a good idea anyway.  The proper way to do that is by using a virtual dir as is done with cgi-bin.  Only the Webserver should be allowed access outside the Webroot, certainly no script should have that ability in a hosted environment.
Of course it should. In fact, this is a weakness in the (current) design of Joomla!, that configuration files are found below document root. Any security relevant file belongs to a directory outside the document root.
camos wrote: Using the live_site variable is essentially the same as using the absolute_path variable
Not at all. The first refers to the structure seen via HTTP, the latter refers to to the filesystem directory structure.

Regards
Niels

Narcissus
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 109
Joined: Wed Sep 07, 2005 5:02 pm

Re: Why use $mosconfig_absolute_path?

Post by Narcissus » Mon Apr 03, 2006 8:52 pm

Hi camos:

Yes. Me saying live_site was a typo, sorry for that.

I know what you're saying about the includes and where the files should be coming from. I agree that it should work that way.

Like I said, though, I just tested this on my machine and it doesn't work that way on my computer. Other people have mentioned the same thing on php.net. Are you telling me that I'm wrong when I say that how it works on my machine is not how you're telling me it works?

(edit)I would like to add, too, that this exact issue is discussed at phphelp.com (http://www.phphelp.com/strands/article/000012.php). Admittedly, it's an older article, so I wonder if this has been fixed in newer versions of PHP. One of the quotes is:

"The relative path to an include file in PHP is always based on the currently executing PHP page. This means if page a.php includes pages b.php and b.php includes c.php all relative include paths in b.php and c.php are relative to the location of a.php without exception."

Lincoln.
Last edited by Narcissus on Mon Apr 03, 2006 9:05 pm, edited 1 time in total.

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Mon Apr 03, 2006 9:14 pm

There is an absolute relationship between the filesystem and the structure seen by HTTP.  One just stops at the Webroot while the other continues from beyond.  Joomla security cannot go beyond where the Webserver will allow it.  Security beyond that is in the domain of the server admin and should not be available to hosted users.  PHP configuration is secured outside the Webspace and the only interaction is through the Webserver.

For portability and usefulness on hosted Webservers it is important that Joomla confine itself within the Webspace and anything otherwise would open doors to itinerant hackers.  Outside the Webspace is secured by htaccess files that should not be editable by users.
Quote from: camos on Today at 03:47:04 PM
Using the live_site variable is essentially the same as using the absolute_path variable

Not at all. The first refers to the structure seen via HTTP, the latter refers to to the filesystem directory structure.
Of course they do, but so far as I have been able to determine, in current use they achieve the same thing which makes one of them redundant.  If this is not so then a specific example of a useage in which mosConfig_live_site does not work would clear things up.

Cheers
Freedom is not free!
It is however Open Source.

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Mon Apr 03, 2006 9:30 pm

Narcissus wrote: Hi camos:

Yes. Me saying live_site was a typo, sorry for that.
I did assume so.  :)
Narcissus wrote: Like I said, though, I just tested this on my machine and it doesn't work that way on my computer. Other people have mentioned the same thing on php.net. Are you telling me that I'm wrong when I say that how it works on my machine is not how you're telling me it works?
I don't know why it would not work on your machine but I agree with the statement in your last para and is what I thought I said in a previous post.
Narcissus wrote: (edit)I would like to add, too, that this exact issue is discussed at phphelp.com (http://www.phphelp.com/strands/article/000012.php). Admittedly, it's an older article, so I wonder if this has been fixed in newer versions of PHP. One of the quotes is:
I looked at the article:
For example: include('/usr/www/users/youruserid/this.site/syndicate_the_news.php'); would include news in your site. If syndicate_the_news.php needs to include any text or php files, a database or XML parser module generating content, then you must ensure all includes in that file are 'absolute' or relative to the web root instead of to the folder of the executing script.
Note this part "are 'absolute' or relative to the web root" which is what I have been saying all along.  Either will work so why keep the hard one?  All Joomla scripts should use or its alternative in order to easily support using sub-dirs and get rid of references to the absolute_path.

Cheers
Freedom is not free!
It is however Open Source.

Narcissus
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 109
Joined: Wed Sep 07, 2005 5:02 pm

Re: Why use $mosconfig_absolute_path?

Post by Narcissus » Mon Apr 03, 2006 9:42 pm

If I include a file with an absolute path in my code (eg. include('/dir/file.php'); ) my servers treat that as the root of my drive, not my webroot. Obviously your situation is different.

Just regarding "For portability and usefulness on hosted Webservers it is important that Joomla confine itself within the Webspace".

A lot of people also use 'external' directories for storing files that they want Joomla to control the access of. For example, outside of my webroot I would have a 'files' directory that I could just store files in. Because it's outside of the webroot, users can't just go to http://myhost/files/filename . Apache can't get there.

Instead, they need to use a PHP script that runs within the webroot to access the file outside of the webroot. It's still just as portable, but you have the benefit of it not being directly accessable.

Regarding the structural usage of live site and absolute path being the same... I would think that there is a bit of a disjoint when using subdomains that are setup as subdirectories of the main site.

eg. sub.myhostname.com is stored in /my/webroot/sub . When accessing the subdomain it's getting rewritten by Apache to point to the subdomain, but the webroot itself is still the same as before...
Note this part "are 'absolute' or relative to the web root" which is what I have been saying all along.  Either will work so why keep the hard one?  All Joomla scripts should use or its alternative in order to easily support using sub-dirs and get rid of references to the absolute_path.
That is true, so long as all files that include the include file are at the same level. The problem with the example is that it was not totally defined: it only talks about what is required for it to work for the given instance, not what is required for it to work in all instances. While so long as you keep all includes relative to the webroot, that is true only for files at the webroot. Once you have a file in a subdirectory that includes a file, all of those included files need to be relative to that subdirectory.

Generally, this isn't a problem. However, if I have a file that includes a library of code, and I have another file in a subdirectory that includes that same library, if the library uses relative paths, it screws up.

Whilever all files that include a string of files are as deep as each other (or as far away from the webroot as each other) there's no problem.

Now, I'm assuming that you don't consider 'include("subdir/filename.php");' to be absolute. Using that kind of relative path could *normally* get picked up by the server as a lot are setup to use the webroot as part of the search path for relative paths...

Anyway, the fact is that this is an issue for my machine and obviously many others...

Lincoln.

Narcissus
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 109
Joined: Wed Sep 07, 2005 5:02 pm

Re: Why use $mosconfig_absolute_path?

Post by Narcissus » Mon Apr 03, 2006 9:49 pm

I'm actually still a bit confused as to how you would even use live_site instead of absolute_path.

Do you mean you would do something like:
include( $live_site . '/dir/file.php' );

Because I know (again, for me at least) that this wouldn't work anyway. Even when include'ing from the same hostname, my Apache will interpret the PHP before including it (as I'm including from a 'remote' stream via HTTP).

Or am I missing something here, too?

User avatar
nibra
Joomla! Guru
Joomla! Guru
Posts: 588
Joined: Wed Nov 16, 2005 2:02 am
Location: Breklum - Nordfriesland
Contact:

Re: Why use $mosconfig_absolute_path?

Post by nibra » Tue Apr 04, 2006 1:28 am

Narcissus wrote: include( $live_site . '/dir/file.php' );

Because I know (again, for me at least) that this wouldn't work anyway. Even when include'ing from the same hostname, my Apache will interpret the PHP before including it (as I'm including from a 'remote' stream via HTTP).

Or am I missing something here, too?
No, Narcissus, you're absolutely right. For some installations it will be possible to retrieve the filesystem path from live_site, for some others not (especially on multisites). Following camos' way makes it necessary, that the filesystem structure and the HTTP structure are identical. It prevents any possibility to use a different mapping for the outer world, which quite often is desirable.

@camos:
Once again: There is no inherent relationship between filesystem and the structure presented on HTTP. Using mod_rewrite or any other kind of SEF, they can differ totally.
$mosConfig_absolut_path is the root of the place, where a script has to look for the files it needs, while $mosConfig_live_site tells the script, what to tell the client browser, where to find resources.

Each standard Joomla! installation covers at least two applications: the frontend and the backend. Both reside in different locations, the first in $mosConfig_absolute_path/, the other in $mosConfig_absolute_path/administrator/. Both have to include a lot of common skripts, joomla.php, component.class.php and so on.
Let's have a look at joomla.php:

Code: Select all

require_once( $mosConfig_absolute_path . '/includes/version.php' );
require_once( $mosConfig_absolute_path . '/includes/database.php' );
require_once( $mosConfig_absolute_path . '/includes/gacl.class.php' );
require_once( $mosConfig_absolute_path . '/includes/gacl_api.class.php' );
require_once( $mosConfig_absolute_path . '/includes/phpmailer/class.phpmailer.php' );
require_once( $mosConfig_absolute_path . '/includes/joomla.xml.php' );
require_once( $mosConfig_absolute_path . '/includes/phpInputFilter/class.inputfilter.php' );
Without $mosConfig_absolute_path it shoul read

Code: Select all

require_once( 'includes/version.php' );
require_once( 'includes/database.php' );
require_once( 'includes/gacl.class.php' );
require_once( 'includes/gacl_api.class.php' );
require_once( 'includes/phpmailer/class.phpmailer.php' );
require_once( 'includes/joomla.xml.php' );
require_once( 'includes/phpInputFilter/class.inputfilter.php' );
That works fine for $mosConfig_absolute_path/index.php including 'include/joomla.php'. But the backend $mosConfig_absolute_path/administrator/index2.php would -- caused by the relative path -- look for $mosConfig_absolute_path/administrator/includes/joomla.php and then for $mosConfig_absolute_path/administrator/includes/database.php and so on.
Without absolut addressing, you have to store all includable files twice or to move the backend files to the same directory as the frontend.
Starting the path with a slash leads to begin the resolving of the path on system root, not on $mosConfig_absolute_path (often, but not always, identical to $_SERVER['DOCUMENT_ROOT']), so that does not help either. By addressing the include files absolutely, they can be included from scripts on different locations within the filesystem.
camos wrote: There is an absolute relationship between the filesystem and the structure seen by HTTP.  One just stops at the Webroot while the other continues from beyond.
It is the default, but there is no necessity for that nor are there any guaratees. On a multisite environment for example, $mosConfig_absolut_path is the same for all instances, $mosConfig_live_site has different values, one for each instance.
Sometimes an URL like example.com/my/files/ maps to /home/virtual/site49/fst/var/www/myfiles/, while example.com/shared/files/ maps to /home/virtual/site49/fst/var/www/files/community/shared/. The relation between filesystem and HTTP you think to see, is pure coincidence.

Regards
Niels

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Thu Apr 13, 2006 4:01 pm

I missed this last post nibra.

Your example is flawed.
require_once( $mosConfig_absolute_path . '/includes/version.php' );

require_once( 'includes/version.php' );
The comparison should be:
require_once( $mosConfig_absolute_path . '/includes/version.php' );

require_once( $mosConfig_live_site . '/includes/version.php' );

Which gets you to the same place backend or frontend.

The only place the absolute_path can take you that live_site can't is outside the Webroot and that does not appear to be needed by Joomla.

Cheers
Freedom is not free!
It is however Open Source.

Narcissus
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 109
Joined: Wed Sep 07, 2005 5:02 pm

Re: Why use $mosconfig_absolute_path?

Post by Narcissus » Thu Apr 13, 2006 4:54 pm

But camos:

What about those servers that don't include files 'directly' if sourced through HTTP?

That is to say, even if the server is trying to include a file via HTTP from itself, many will still parse the file: they don't just pass it to you. They act as if it was just a normal client calling the file via a browser, for example, parse the PHP and then pass the output. Naturally, this breaks stuff if you include a file that way.

Again, just like including from other directories, different servers do different things. You're obviously lucky in that your server includes files from different directories correctly and includes files called via HTTP correctly. Unfortunately, many do not.

It just seems as though no matter how many times we say this throughout the thread, you just pretend as though it isn't true...

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Sat Apr 15, 2006 5:23 am

As far as I can tell within the normal Joomla dir tree there is no appreciable difference between using $mosConfig_absolute_path or $mosConfig_live_site to locate a specific file.  I don't understand the point you are making.  We are not referencing files directly from the browser but rather running PHP scripts that access files.  An improperly set up php.ini that leaves out the initial . in the icludes dir setup will probably not work with either form of the path variable if that is what you are referring to.

I have seen nothing in any of the previous responses that validates the use of the absolute_path except possibly near the beginning which at best was only a possibility since I did not really get the point.  The rest are either urban legend or inaccuracies that cannot substantiate a statement that it is indeed true.  Perhaps your point is valid but it is going over muy head.

This question was initially just an idle curiosity that I thought someone might be able to answer.  In the mean time in another really, really long thread where some inexplicably weird problem was being discussed, the solution turned out to be that the admin had changed the absolute_path without announcing it.  It would appear this question of mine may have some merit.

Cheers
Freedom is not free!
It is however Open Source.

Narcissus
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 109
Joined: Wed Sep 07, 2005 5:02 pm

Re: Why use $mosconfig_absolute_path?

Post by Narcissus » Mon Apr 17, 2006 1:10 am

OK, so the basic premise of the problem with using the live_site value is this... bare with me, I need to set up a few things :) Also note that I will say 'half the servers' do this and 'half the servers' do that. I obviously don't mean half exactly: I don't know the percentages but I do know that both are 'a significant percentage', that is, enough to worry about on both sides :)

Imagine a PHP file with something like the following content:

Code: Select all

<?php
$global_a = '1';
$global_b = '2';

print 'Hello World!';
?>
Imagine, for the sake of this discussion, that this is stored in the file 'demo.php' in your Joomla root ($mosConfig_live_site . '/demo.php'). I will pretend as though your live_site value is http://www.mysite.com/joomla.

So, when your browser calls http://www.mysite.com/joomla/demo.php, the server reads the PHP file, parses the file then passes the output to your browser. In it, you will just see...

Code: Select all

Hello World!
It may seem obvious, but it's important to note that after parsing the file and passing the output to your browser, for all intents and purposes the two variable definitions don't exist. All your browser gets is the printed string.

Now imagine you had a script in your Joomla root called demo_includer.php:

Code: Select all

<?php
include( $mosConfig_absolute_path . '/demo.php' );
print 'global_a = ' . $global_a;
print 'global_b = ' . $global_b;
print 'Hello World from demo_includer.php';
?>
If you send your browser to http://www.mysite.com/joomla/demo_includer.php, you will see:

Code: Select all

Hello World!
global_a = 1
global_b = 2
Hello World from demo_includer.php
The first string comes from the print that is executed when including the demo.php, then you see that the variables are defined and used by the demo_includer.php script.

Note that that is what happens when you include using the path. In this instance, you didn't need $mosConfig_absolute_path as it was in the same directory, but I used it for completeness.

Imagine, now, this file (that we will call demo_includer_live_site.php), instead:

Code: Select all

<?php
include( $mosConfig_live_site . '/demo.php' );
print 'global_a = ' . $global_a;
print 'global_b = ' . $global_b;
print 'Hello World from demo_includer.php';
?>
Note that we now include by using the live_site variable.

The line:

Code: Select all

include( $mosConfig_live_site . '/demo.php' );
ends up looking like:

Code: Select all

include( 'http://mysite.com/joomla/demo.php' );
after the $mosConfig_live_site variable is used.

Now, what happens when you call http://www.mysite.com/joomla/demo_inclu ... e_site.php from within your browser?

Unfortunately, this is where things get murky. Half the servers will output:

Code: Select all

Hello World!
global_a = 1
global_b = 2
Hello World from demo_includer.php
this is because when you included the file with the live_site variable, PHP realises that it is including a file from its own server. It knows that http://www.mysite.com is itself and so knows to include the file directly. That is to say, it opens the file from the file system, parses it and has all of the information. When we include a file, we essentially replace the include line with whatever is found within that include file. We end up with the code:

Code: Select all

<?php
$global_a = '1';
$global_b = '2';

print 'Hello World!';
print 'global_a = ' . $global_a;
print 'global_b = ' . $global_b;
print 'Hello World from demo_includer.php';
?>

However, half the servers will give you:

Code: Select all

Hello World!
global_a = 0
global_b = 0
Hello World from demo_includer.php
Well, actually, it will give you a parse error, but I'll get to that :)

Why does this happen?

When PHP on these servers sees that it is including a file via HTTP, it doesn't realise that it can shortcut itself and so load directly from the filesystem. It literally makes a HTTP request to itself, asking for http://www.mysite.com/joomla/demo.php. This is what I was referring to when talking about the browser. The data that is returned from this HTTP request is just like what you get when you call it from the browser. So, like when including a file from the file system we essentially replace that line with the code found within the file that we are including, in this instance we replace the include line with whatever is returned from the HTTP request.

We essentially end up with:

Code: Select all

<?php
Hello World!
print 'global_a = ' . $global_a;
print 'global_b = ' . $global_b;
print 'Hello World from demo_includer.php';
?>
Hence, the code doesn't actually know what the variables '$global_a' and '$global_b' are: they are never defined by what is included.

Like I said, it actually would give you an error as the first line is not valid PHP.


Does that make any more sense? I'm crossing my fingers because I don't know how much better I can explain it :)

Lincoln.

User avatar
nibra
Joomla! Guru
Joomla! Guru
Posts: 588
Joined: Wed Nov 16, 2005 2:02 am
Location: Breklum - Nordfriesland
Contact:

Re: Why use $mosconfig_absolute_path?

Post by nibra » Mon Apr 17, 2006 1:50 am

Narcissus wrote: this is because when you included the file with the live_site variable, PHP realises that it is including a file from its own server. It knows that http://www.mysite.com is itself and so knows to include the file directly. That is to say, it opens the file from the file system, parses it and has all of the information. When we include a file, we essentially replace the include line with whatever is found within that include file. We end up with the code:
I have never seen, that files included via the url-fopen-wrapper were not interpreted before including. IMO a server taking the short way through the filesystem is heavily misconfigured. Variables from a script included via URL have not to be seen in the scope of the including script. The included script (via URL) is not allowed to see the variables of the calling script either.

Beside that, a quick look into the PHP manual makes absolutely clear, why both variables are necessary:
Note:  In PHP 4.0.3 and older, in order to use URL wrappers, you were required to configure PHP using the configure option --enable-url-fopen-wrapper.

Note: The Windows versions of PHP earlier than PHP 4.3 did not support remote file accessing for the following functions: include(), include_once(), require(), require_once(), and the imagecreatefromXXX functions in the Reference LX, Image Functions extension.
In addition, on many virtual hosts the url-fopen-wrapper is disabled, even on newer PHP installations.

Regards
Niels

Narcissus
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 109
Joined: Wed Sep 07, 2005 5:02 pm

Re: Why use $mosconfig_absolute_path?

Post by Narcissus » Mon Apr 17, 2006 2:12 pm

Thanks for the feedback nibra.

To be honest, I've never seen the activity I described and I agree that it would be nasty if it did. The only reason I said that it did was because of how I've read certain comments around the web over the last few weeks: my reading is quite probably bad, though!

My lord, you know you're old when you start reminiscing about the days where every second PHP config file was config.inc and the insights you could get by just calling it directly from within your browser :)

Your other points are also great.

Thanks!
Lincoln.

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Why use $mosconfig_absolute_path?

Post by camos » Mon Apr 17, 2006 3:30 pm

I think I get your point now Lincoln, thanks for your explanation and your patience. 

Same to you Neils, your link helped to clarify what Lincoln was saying.

Cheers
Freedom is not free!
It is however Open Source.


Locked

Return to “Joomla! 1.0 Coding”