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