I have a number of web sites that are related but separate. They all share a database on the same server. For example, the candle site will query the candle information. The discount site will query the discount information.

Each of the sites use the same functions to call information from a database. I just pass different values to the functions to query the correct information. However, each site has its own function php page which means when I update a function on one site, I have to do it on all of them. I'd like to have them all be able to include the functions from one master function page.

Can I use a php include statement to include pages from another domain?

For example:

// candles.com and discounts.com could be two sites
// will this work on candles.com?
include('http://discounts.com/myfunctions.php');
    mrgrammar wrote:

    Can I use a php include statement to include pages from another domain?

    Yes if urlfopen wrappers are enabled, but you will get a HTML page, not a PHP script, which in this case would be totally useless to you since it would presumably be blank.

    mrgrammar wrote:

    Each of the sites use the same functions to call information from a database. I just pass different values to the functions to query the correct information. However, each site has its own function php page which means when I update a function on one site, I have to do it on all of them. I'd like to have them all be able to include the functions from one master function page.

    Use the same file path instead of a URL. However, while this can work, in the long run you may find that you cannot feasibly upgrade different sites to use newer versions of your library all at once, e.g., because you have to introduce some backwards incompatibility. Version control could help.

      No, and if you stop and think about it, it should be obviously why that would never work... rather, you should hope that would never work. Otherwise, what's to stop me from include()'ing random PHP files from your website, perhaps one that contains your database login credentials?

      If the domains reside on the same physical server (or, at least, are on servers that have access to the file systems of each other), then you'd want to use the local file system (as usual) to access the common file. The file path would, of course, depend entirely upon the structure of the file system(s) at hand. This is also assuming that neither file permissions nor PHP configuration would prevent scripts executing for one domain from accessing files stored for another.

      EDIT: Still wishing we had that lovely "wait, someone posted while you were composing a reply" interim page that even free forum software offers. 🙁

        [EDIT] or what they said 😉 [/EDIT]

        The problem with that approach -- at least straight "out of the box" -- is that the PHP file would be parsed/executed by the web server, and the calling script would only receive the output (if any). You could change the file name suffix so that it's just served up as plain text, but then anyone who happens to make a good guess (or know something about your config) could view your PHP source code, which is usually not a good thing.

        If all the sites are running on the same web server, then it should be possible to put the include file in a location accessible to all of them, possibly outside of the web root directory hierarchy.

          Write a Reply...