Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWebsite Development and Maintenance

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Updating Identical Content Across Domains

For site owners with several domains, some content may be identical across domains. This may be contact information or a contact form, as examples.

Updating each one individually and verifying they're all correct can be time consuming. Unless all domains import the identical content from one central file. Then, updates are relatively easy.

There are several ways to import the content.

Importing Content With PHP

Create a central file containing the content that must be identical on all domains. Upload it to your server and make a note of its URL.

Put this PHP code on the web pages where the information is to be published (change the http://example.com/content.html URL to the URL of the central file).

<?php readfile("http://example.com/centralfile.html"); ?>

If your PHP does not allow the readfile() function to use http://... URLs, ask your hosting company to enable fopen wrappers. (More information at this page.)

Importing Content With JavaScript

Use the the Text to JavaScript Converter. Either upload the converter web page to your website or use the example installation linked from the above article.

Use the Text To JavaScript Converter to convert the content that must be identical on all domains.

  1. Save the converted JavaScript to a file with a .js file name extension.

  2. Upload the file to your server.

  3. Make a note of the .js file's URL.

Next:

  1. Copy the JavaScript to import the file that the converter also provides.

  2. Change the src URL to the URL of the .js file on your server.

  3. Paste the JavaScript to import the file on the web pages where the information is to be published.

Importing Content With SSI and CGI

SSI can not import content from a different domain. But CGI can. Therefore, a CGI programed is installed on each domain that the SSI can import from.

First, create a central file containing the content that must be identical on all domains. Upload it to your server and make a note of its URL.

Now, install the following CGI script on each domain, in a directory that can run Perl CGI scripts (instructions follow).

#!/usr/bin/perl
$URLofCentralFile = 'http://example.com/centralfile.html';
use LWP::Simple;
print "Content-type: text/html\n\n";
print get($URLofCentralFile);
exit;

To install:

  1. Copy the above code and paste it into a plain text processor like NotePad or TextWrangler.

  2. Replace the http://example.com/centralfile.html URL in the script to the URL of the central file created earlier.

  3. Save the file with a .cgi file name extension.

  4. Upload the file to your server with FTP as a plain text file (not as a binary file).

  5. Give the uploaded file 755 permissions.

Test each installation by typing its URL into your browser.

Make a note of the script's URI as it will be needed for the SSI tag. The URI is the URL minus the domain name information. Example: URL http://example.com/cgi-bin/contentscript.cgi is URI /cgi-bin/contentscript.cgi

Here is an example SSI tag to put on the web pages where the information is to be published (replace /cgi-bin/contentscript.cgi with the URI (not URL) of the CGI script.

<!--#exec cgi="/cgi-bin/contentscript.cgi"-->

The SSI tag executes the script. The script grabs the central file and sends it to the web page with the SSI tag.

If the above SSI tag doesn't work (some hosting companies block the SSI "exec" command), try this code (again, update the URI).

<!--#include virtual="/cgi-bin/contentscript.cgi"-->

Importing identical content into several domains from one central file can save a lot of time otherwise spent updating each domain separately.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC