I got curious about includes and started experimenting with an idea.
On my site, www.xyz.com, I can include a page from another site, www.efg.com, and it shows that whole page. In other words, the only code on www.xyz.com/page.php would be:
include "http://www.efg.com/pagename.htm";
and www.xyz.com/page.php displays www.efg.com/pagename.htm.
Of course, I don't need to display pages from other web sites, but the ability to do so got me thinking. I have several web sites that share the same set of code. All the sites are located on the same physical server although they have different domain names. It would be helpful to edit one time and affect all of the sites. Therefore, I set up a code page in a central location and referenced it from an external domain.
Central location, www.central.com/code.php has the code:
$number = $a + $b;
External location, www.xyz.com/index.php, includes the page from the Central Location.
$a = 5;
$b = 2;
include "http://www.central.com/code.php";
echo $number;
Here's the problem: code.php does not recognize the variables $a and $b. I did find that code.php will recognize variables passed in the include statement:
include "http://www.central.com/code.php?a=5&b=2";
And index.php does not recognize the variable $number that should come from the central location (code.php). Therefore, $number does not display on index.php.
My assumption was including the file from code.php would execute the code as if it were part of index.php. Why won't the variables work like I want them to?