Ok, so this may be an odd question but I am just not sure about this.

I have a customer who has multiple sites with the same content on some pages. We are trying to figure out if there is a way using some type of include file if we can have the multiple sites pull from a central group of data files (could be text or whatever is needed).

Working with UNIX and traditional html but could to go windows/.net if needed.

Any ideas or suggestions? Is this even possible?

Thank you for your input.
Dewayne

Dani AI

Generated

: this is absolutely possible. @ingeva's idea of a centrally-managed set of includes is a solid starting point when you control the host. Below are practical, modern alternatives and the key caveats to decide which fits your environment.

If all sites live on the same server

  • Mount a single shared directory into each vhost (preferred to duplicating files). Use Apache Alias or the equivalent Nginx alias so each virtual host can reference the same path without fragile symlinks (Apache Alias, Nginx alias).
  • For PHP-driven sites, centralize common PHP logic with auto_prepend_file or by adding the shared path to include_path so each site automatically sees the same library (php.net include_path, php.net auto_prepend_file).
  • For static fragments (headers/footers) consider server-side includes (SSI) with mod_include to include HTML snippets at request-time:
    <!--#include virtual="/shared/header.html" -->

    (Enable only if your host allows it: mod_include).

Security, permissions and runtime caveats

  • Check open_basedir, PHP-FPM pool ownership, suEXEC/suPHP and SELinux contexts. These controls can block cross-site file reads if the web process user lacks rights (php.net open_basedir, PHP-FPM).
  • Never use remote HTTP includes for trusted code (allow_url_include). It hurts performance and security.

If sites are on different servers

  • Use deployment/sync methods: a shared git submodule or subtree, rsync during deploy, or a private package pulled via Composer for PHP logic (git submodule, Composer docs).
  • Alternatively place static assets on a central storage or CDN and reference them from each site.

Troubleshooting checklist

  • Use phpinfo() to confirm include settings, check webserver and PHP error logs for permission/path errors, and verify file ownership and mode.

Recommended Answers

All 2 Replies

Member Avatar for Member #360561

Ok, so this may be an odd question but I am just not sure about this.
I have a customer who has multiple sites with the same content on some pages. We are trying to figure out if there is a way using some type of include file if we can have the multiple sites pull from a central group of data files (could be text or whatever is needed).
Working with UNIX and traditional html but could to go windows/.net if needed.
Any ideas or suggestions? Is this even possible?

I have done this for a long time. Recently I've come up with a more secure solution: I have one index file which is common for all my sites (except those made with Joomla!). Also, this index file defines the default include directory so all sites can use the same one without even knowing its location.
The index file handles existing and non-existing files (like a 404 error handler) and directories for all the domains on the host and finds the "real" location for the domain or subdomain. This way I don't have to declare subdomains in Cpanel; all I do is to create a directory for them. This is not necessarily possible in all hosts.

My index.php file looks like this:

<?php
require ".common/.php/.phplib.php";
require MAINFILE;					// Now go to site.
?>

Naturally, MAINFILE is the "real" index file (found by .phplib). All headers and declaractions are done so all that's needed is to end the </head> section (unless there's more to be added) and start <body>.

.phplib.php contains all the start code and some often used functions, and defines a whole lot of constants and variables for ease of site programming.
The rest of the php include files are in the same directory, which is set in php's include PATH. There are also directories for the CSS and JavaScript files, and there's really no limit to how many common directories you can declare.

I have zero knowledge of MS .NET but I don't expect it to be very different, except MS AFAIK doesn't have a .htaccess file so it may not be possible to configure the same way.

This didn't have much to do with html or CSS, but please excuse me this time ... :)

ingeva -

Ok, I have excused you for not sticking with htm or css. Not even sure it's possible with those! : )

Your solution is very creative and woud work with some changes for us! Thank you so much for sharing your knowledge!

Dewayne

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.