Common files for multiple sites?

I’m new to this forum and new to web programming, but I am trying to learn.

I’m trying to do something and I want multiple web sites on different hosts to be able to draw some common information from a single site.

Not really sure how this can be done, but I’ve looked at this from the perspective of wanting to include one file into another.

That brought me to this:
How do I include one HTML file inside another?

This opened the topics of Server Side Include, CGI, JavaScript, and Perl. I’m also thinking that as it seems to come to using Perl, that I might want to use PHP instead. So I’ve been trying things and reading books.

  1. <!–#include FILE=“” –>

This works. I wasn’t sure which extension to use on the file to be included. So I picked .ssi. Looks like there is some acceptance of this.

But then for the file to do the including, one is to set the execution bit or use an extension which indicates that it is to be executed.

I am doing this on free web site hosting accounts so I have no Unix shell login. Not sure how to set the execution bit, but from Unix experience long ago I think it not the same as the permissions mask. I do make sure that I have 755 permissions which does allow execution.

I use the file extension .shtml instead of .html and this seems to work. Server Side Include is already doing a great deal for me in terms of making sites easier to maintain.

  1. But, Server Side Include does not seem to allow taking stuff off of another server. It does not even seem to allow absolute URLs, even if they just point back to the starting place.

With one free account you get multiple subdomains and they each have their own subdirectories. It does not seem possible to use Server Side Include to get any files from another of the subdomains, instead of those in its own tree.

  1. With one server I have not been able to get Server Side Include to work. It looked like it was working. I thought it was. But now it seems to just skip it. No error message, it just skips it. This server has a .htaccess file. So I presume that I need to add something to this file, and maybe make another such file in subdirectories where it is needed?

  2. <script src=“b.js” type=“text/javascript”> </script>
    I try Notenboom’s next suggestion. Yes, I was able to get a JavaScript file and in that file I used document.write statements to make HTML and this worked. I was able to take the JavaScript file off of another server!

But I was not able to take it off of the Apache server though, as Notenboom says. I did try it.

Didn’t try drawing it in to the Apache server from elsewhere.

JavaScript requires a separate document.write for each line of HTML/CSS?

I tried just including a big block with the carriage returns and it seemed not to work.

  1. So I want to do something like Notenboom’s CGI method:

use LWP::Simple;
print "Content-type:text/html

getprint ($ENV{‘QUERY_STRING’});
We’ll call it “”. must be appropriately installed on your server into your cgi-bin directory or its equivalent. By being local to your server, Include directives can reference it. simply fetches the contents of the URL passed as a parameter. This means we can perform an apache remote include this way:

<!–#include VIRTUAL=“/cgi-bin/” –>

So first of all I have had to do some reading to even understand what this all means. I have been reading about Perl and about PHP.

It looks like PHP is on more free web site hosts and looks like maybe more people are using it for somethings today.

Can I do something like above with PHP instead of Perl? Is there any reason I should be learning Perl instead of just PHP?

  1. So I read about GET and POST, ways to pass data from HTML forms to server scripts. Looks like both Perl and PHP do both just fine. GET is like what Google does, adding characters after the web address, and then they show up in an environment variable. POST uses the Stdin stream. I’m familiar with both of these from decades ago writing C langauge programs for Unix, and also for DOS. Never have liked Windows.

So the above uses GET.

All of the books about CGI talk about it relative to Perl. I even read one book which lists about 8 computer langauges where CGI is also used. But they don’t mention PHP.

Does PHP use CGI, just about the same as Perl? Does it have some other way to do things, so you don’t need CGI? They never seem to talk about it in the PHP books.

  1. Looking at what I want, some common HTML to be used by a bunch of sites, all on free hosts, is some CGI and PHP based remote include the way to do it?

  2. Microsoft seems to have lots of proprietary programming langauges, protocols, etc. They always have this. I got burned in the late 1980’s with their OS/2. I had lived under the 640k limit for MS-DOS and was ready for something multitasking, with more memory, and with virtual memory and planned to be involved with it. I got burned.

Most of the Microsoft proprietary stuff never seems to work very well and eventually craters.

  1. Perl seems to allow printing big blogs of text, with the carriage returns, from a signal print statement. You just have to make sure there are no spaces or blank lines. Does PHP allow something like this? Seems like it should.


As you’ve seen, include files only work within a single site. There are content management systems that allow you to run multiple sites on one server that share files, but that’s still not what you want.

One option you didn’t mention, which is quite simple, is to use the <object> element to embed remote pages on a web page. It works like this:

<object data=“” width=400 height=500>

Only problem is, older browsers don’t recognize the <object> element, but an alternative that all browsers recognize (though it’s not an official HTML element) is <iframe>, which would look like this:

<iframe src=“” width=400 height=500>

Is that a big problem? I was using <object> to pull in sub-pages nearly 10 years ago, and I wasn’t aware then of any ‘modern’ browsers that didn’t support it.

You can always put some text and a link to the data source inside the <object>…</object> tags, which will only be rendered in browsers that don’t support it.

A key difference between server-side includes and the <object> tag is that with an include, the content is pulled into the referring page, so you only code up a fragment – whereas the data source referenced in an <object> tag has to be a stand-alone page with its own stylesheet information; it exists independently of the parent page. Obviously, this has implications for pulling it into different sites if the styling needs to be different for each one.

Yes, sorry, my wording was wrong. I’m just aware that older browsers like IE6 have troubles with <object>, though they do recognize it. Felgall has some interesting tips here:

Felgall Replacement for iframe Tag

Ralph you are having a bad day with the words IFRAME is valid within (x)html. Although it’s an awful element and was deprecated within HTML 4.01 but the wondrous Fred seems to want it back.

OBJECT is well-supported in modern browsers though a certain vendor had major issues implementing it correctly. OBJECT just links/embeds an external object file.

PHP should be able to do what you are after. SSI is restricted whereas PHP is more powerful and can pull data from other domains. The term ‘PHP include’ might be what you are after for example: <?php include (“somedirectory/footer.php”); ?>

I’m going to have to try out lots of things to learn the details and the limits of the various things you have suggested.

ralph.m spoke of content management systems. Long term, I think this is the sort of thing I would like to be building around. Any of these available free? Any I could install on a free web site host?

Always we have programming languages and then before too long we are writing programs to generate them. The Unix and old MS-DOS approach with streams and piping was the right way. Not Windows and the MacIntosh Graphical systems. Eventually we need our own parsers of the languages so we can do preprocessing too.

As far as object and iframe I had not considered that. I hope it can be done without having to specify width and height. As what I have done is specifically built a page that uses Tables instead of Div. Everyone promotes Div and float alignment as the way to make columns. From what I have tried, unless you want to use Em’s for width, then you have to go fixed width.

Most corporate pages nowdays a fixed width, and I don’t like it. I think one of the strengths of the medium is that it can adjust to monitor and viewing port size. I like to watch how it re-adjusts carriage returns to adapt to viewing port size. I’ve learned to use margins on my text and padding on my boxes so that it always looks nice. So I like using Tables and variable width for the top level.

If you set all padding and boarders to zero on everything, including TBODY, then on most browsers there are no gaps.

Old IE does not understand min-width, but it does understand max-width. So to get min-width you just jam some centering Div in there, or even a Div with height = 0px. It all works, as I’ve spent lots and lots of time stress testing it.

Usually there is some relationship between text which is left aligned and which is center aligned. If you let the width vary too much, this is lost. So there have to be some limits.

I feel I’ve got something which works well on all monitor sizes now. So I do want flexible width. Flexible width uses more browser smarts than does fixed width.

About having to have complete pages to iframe or object, with style sheets. No, I don’t want this. I would have to rethink a great deal. What I want is to just handle code blocks, not complete pages. My blocks get included into pages which also link to style sheets.

About what Notenbaum suggests using CGI and Perl, I have spent time reading and thinking.

The key Perl line is :
getprint ($ENV{‘QUERY_STRING’});

Its this getprint function which allows you to dump huge text blocks, even though they contain carriage returns.

Being able to pass the file name as a GET parameter is secondary.

I guess the idea with Apache is that if someone can just start accessing server scripts in whatever way they wish, then probably they can get around password protections and maybe even be able to tap into data bases.

So the Perl script has to be on the computer you want the data to go too, not the Apache server you are trying to get it out of.

The same would apply if one used PHP.

When Apache will give up the file, it does it because it thinks it is just servicing an HTTP request, just like a browser would make.

So as far as:

<?php include (“somedirectory/footer.php”); ?>

It would seem that this would only work if the php script is on the server you want the file to go to. As again, I gather that an Apache server will not grant you access to its scripts, or the ability to just retrieve one of them so you can run it. This is what I tried with Java Script. This is what Notenbaum says. The Apache server won’t let you do it.

I have not yet learned how to write programs in php. But I extrapolate from what xhtmlcoder wrote and I imagine:

<?php include (“”); ?>

And again, this script has to be on the local server, where as is where I would be keeping my central file repository.

Lots of trial and error I am having to do. This is why I am now posting here.

No Signature Newbie

Here I find this about php include. I note example #3
PHP: include - Manual

So unless I am using Windows PHP prior to 4.3, then it looks like it should work. I presume it will even work on an Apache server, even one where I have not set up its .htaccess files to allow it to execute. Because I am not trying to run the PHP on it. I am just trying to get a non-executable web page like file out of it.

Much to try and much to learn.

If this works, then I can look at passing information to the script via GET and POST. But for right now, especially as it looks like this PHP can just sit right in my HTML file, ant it is so short, maybe I don’t need to pass file names as parameters.

Going to start trying it now.

I tried it and it doesn’t work.

: URL file-access is disabled in the server configuration in …

Above is what I got.

First of all, it did not seem to want to execute my php in the file ending .shtml. So I changed it to .php.

Then the php executed. I had one echo statement in it and that worked. But that above is what it did with the include which had a url.

Then it had susequent errors pertaining to the same line, as the file was not opened.

So I assume this is coming from the server I am trying to run my php on, not from the apache server I am trying to retrieve a file from.

I also notice that with the file which ended .php, it failed to run my Server Side Includes, where as they had been working in the .shtml file.


Not sure what to try next.

Make sure your servers are setup to allow PHP. You said you were using free hosts and many free hosts heavily restrict the functionally of PHP or only allow SSI.

SSI and PHP cannot both be used on the same webpage - you have to have one or the other per page. I assume you have tried downloading something like XAMPP for basic offline testing?

So let me review where I am at:

  1. XAMPP for basic offline testing?
    I am not aware of what this is, but I will look into it.

  2. Havng to find out what these free web site hosts can and cannot do IS the problem. Its trial and error in the dark and so it is time consumptive. But this one has responded to me. They say that they block attempts to get remote files. So I guess this means via PHP or Perl. They say I would need a paid account and to ask to have the restriction lifted.

I guess they want paid accounts and I guess they want to limit the propensity for some sorts of mischief.

I can’t even get up a directory one level and then back down to another free subdomain’s files on the same account.

  1. I guess the only reason JavaScript remote works is because they can’t block it.

Some free web site hosts, like Google Sites, edit your code. This irritates me because they mess up the formating and readability.

  1. So I guess I could just live with it all. I can link to stuff on an outside host. I could just make some needed replications and keep everything on this other place.

  2. They allow you to link to outside pages. I think I can use the GET method to pass info to them. So I could decode this with PHP and then create the page as so indicated.

  3. I still don’t have the Apache server executing files. But I believe making an .htaccess modification would fix it.

  4. I could explore the limits of iframe and object. But a free web site host could have these restricted too.

  5. If I use JavaScript, I do seem to be able to get stuff off of other sites, except the Apache server.

If I use JavaScript do I need to have one document.write per line of HTML, or is there a way to include big blocks with the carriage returns?

  1. Seems like there should be someway to have the broswer request a file in such a way that an Apache server sees it as web page request and therefore will honor it.

  2. So if I use SSI I name my files with .shtml. If I use PHP I have to use .php and stop using SSI? I guess I use php’s include() instead?

  3. Yes, I like the idea that PHP code can sit right with HTML, using ? as its identifying tag.

  4. Perl has the hash variable type. This looks like struct in the C language. Perl also has some sort of indirection in function calls, like C’s pointer to function. Most complex C langauge programs center around such things. So Perl is attractive for more complex programs. Not sure if PHP has these.

  5. yes, this is item 13. I feel that the entire web page programming environment is too much of a hodgepodge. Too many ways of doing things, too much stuff that no one uses because it doesn’t do what they want. Just too complex for what is being attempted. Too little error detection, too much guess work and trial and error.

I guess the original idea was just to be able to replicate the structure of academic papers. So you have the definition lists and all. But the expectations about specific style and formatting were relaxed.

But today the standard has been raised to a general purpose and full fledged client-server environment.

It is really messy and still too limited.

No Signature Yet

More trial and error in the dark!

I can’t resist trying out iframe. So I go to the tryit editor.

It does seem to work on a MacIntosh running FF. But if I change to object it does not work!

If I try and iframe one of my own pages it works.

So I go to one of my hosts and use iframe in a page of my own and try to iframe another one of my pages? Yes, it works!

Looks like I can set width to 100%, and this means of space available and this is what I want, as my layout is tabular.

I can turn scrolling off. I can set height to 100%, but this is does not really seem to understand!. Should be 100% of space needed.

I can turn the border off.

I am just trying HTML tags on the iframe, not CSS.

Now the real test. I try to drop the style rules out of what is being iframed. Will it follow the operative style rules?

I try to download a page of min to the MacIntosh hard disk and iframe it off the hard disk. This does not work. Seems like it should. So I go back to iframing it off of a free host.

Yes it sort of does, for text and background. But the table structure does not follow the rules and the alignment does not either.

So I try with one of my files intended to be SSIed or PHP include()ed. This will have all the right class and id names. Still does not work.

So I follow what the try it editor does and have html and body tags to make it into minmally legal html. Still does not follow the operative style for tables and alignment. I am using CSS exclusively. Not a single HTML attribute.

So this means that if I am to host 10 versions of a resources page on a common server, I need the 10 style sheets to be there too.

Not so elegant.

So I think what I will do is just pool the ten versions of the resources page on a single outside server and just link to them. Simple enough! Crude but effective.

No problems with what the servers do or don’t allow in terms of remotes.

Yes, I will have to have the 10 style sheets there. I guess I could use a single .php file and I guess I can use php in the header portion, I think. So then I could use GET and pass a parameter and switch style sheets on the basis of that. I could make other content switches too. Or I could just have my 10 versions of the .html. It could be 10x .shtml’s with SSI being used, or 10x .php’s with include() being used. No matter what the only inelegant replications are the base stylesheets for the 10 sites.

These change much less often than the page contents.

So maybe for now I have my direction. Need to sleep on it.

Does IFRAME work here?

<iframe width=“480” height=“390” src=“” frameborder=“0” allowfullscreen></iframe>

Iframe is supposed to be like img I take it.

Doesn’t work in preview. <snip/>

As you have found out usually “free hosts” restrict things a lot more. Like I mentioned, so their service doesn’t get abused, by power users, and they have more control over your content, etc. Though proper paid web hosts aren’t that expensive and don’t fiddle with your code.

Client Side Includes are HTML includes achieved on the client-side. For example including files with JavaScript. Not usually a really sensible idea for proper large text only inclusion. From what I gather; you are basically after actual page includes to merge into your page.

OBJECT is a ‘replaced element’ so yes; in effect it is the same as IMG with more scope than just ‘images’ but just embeds a whole file object - not merging of data (still a separate independent file).

The .htaccess determines how your extensions are interpreted. I use PHP includes on my site on about all pages - the extension is set to .xht or *.htm in places. Though it still gets parsed and treated as PHP: AddType application/x-httpd-php .xht

So if you had a “paid host” then you probably could give your HTML files; *.donkey, *.pig, *.kangaroo extension, etc. Thus have them treated as PHP. So the extension doesn’t always have to be *.shtml or *.php but they are the typical ‘default’ MIME in Apache for PHP and shtml.

Yes, PHP is far superior and SSI is very limited and SSI is only typically used by the poor-man, i.e. free webhost accounts.

So again I review where I am at. I’ve been reading about PHP. Yes, it does seem to have everything, like some sort of object orientation, passing variables by reference, and associational arrays. So I would think that for HTML, PHP would be the best, as it sits inside the HTML.

Perl maybe would be good for writing stuff to be used in conjunction with C programs. I hear that Apache is written like this.

So I could do what I want by putting everything for my resources page on a server. This would include the base style sheets from the other sites which would use this. I could have ten files to call. Or I could pass a parameter by GET or POST and then use PHP to switch on this.

I beleive PHP can work in the header area, so it could decide which style sheet to include. Maybe JavaScript can switch on GET or POST variables too?

I’ve not seen that PHP can print big blocks of text including carriage returns from a single print statement, but I guess it works out somehow.

I’ve looked into iframe abit more, into what more might be done if one styles it with CSS.

‘iframe’ CSS Attributes and JavaScript Style Properties : iframe « HTML Tag Reference « HTML CSS Reference

I go thru this and its quite complicated. I’m still seeing height as a problem. That is, I want it to be 100% of the height needed for the material included. This is how it would be if the material were included with SSI or PHP’s include(). Not seeing this.

But about stylesheets this is interesting. It says you can include a stylesheet from the parent page into the child page. Could this actually be done remotely? If so, this would solve all of my problems. I would of course not need to use iframe at all then.

  1. Can the standard way of linking in style sheets work remotely?

They say you can use JavaScript to load a stylesheet. Not familiar with this either, I just look at their example. If this could work remotely this could be a second way.

  1. Does this JavaScript way of loading a stylesheet work remotely?

How do I include one HTML file inside another?

This example of his did work for me:

<script src=“” type=“text/javascript”> </script>

I included one line this way using a document.write statement. It worked on all but one blatant Apache server.

xhtmlcoder wrote:
/* For example including files with JavaScript. Not usually a really sensible idea for proper large text only inclusion.*/

I think by this he means the workings of the document.write or doc.write statement. Not sure how this goes with big text blocks. The above thing about IFRAME gave one example.

Yes, I’ve got to explore what needs to go in the htaccess file so I can get the Apache server executing.


Here someone has tried linking to a remote style sheet. They are writing about it because it’s not working. But the stackoverflow people don’t see it as out of bounds.

If that is possible, it would solve all of my problems.

Then a little bit of PHP or JavaScript to be able to decide which style sheet gets remotely loaded based on something passed via GET or POST would be the icing on the cake.

To try to fix it stackoverflow gets into this:

Look here, Apache Friends (PHPbb)
Apache Friends Support Forum • View topic - problem running a page containing remote link

This person tries it. They are posting because stuff is not working. The problems sound complex. But the respondent doesn’t seem to rule remote linking out of bounds.

Maybe this too:
CSS remote link help CSS forum at WebmasterWorld

Here someone asks, and the answer is unclear to me:
Adobe Forums: Remote stylesheet possible?

I look at two familiar HTML / CSS books. They both show using the regular
link rel=“stylesheet” href=“stylesheet.css” type=“text/css” being used with absolute URLs. One specifically says that it will work with anything the user has HTTP access to.

The other book also shows the @import method.

Some years ago I had tried this, locally, and not been able to get it to work.

I’ve got another book now about JavaScrip and DHTML. It does say much about manipulating stylesheets.

But if I can get remote style sheet loading to work, I’ve got the minimum requirement met. Going to PHP to switch on something passed via GET or POST gives me all I would hope for.

This is reversed from what I had intended. But it makes sense as the one thing never in doubt is that it is possible to get the browser to display pages external to what is calling them.


This works with an absolute URL to a different server:
link rel=“stylesheet” href=“stylesheet.css” type=“text/css”

I’ve got a bunch of them, so I’m going to try a few. The other ones won’t match the HTML for the page, but that’s okay.

So the most critical problem is solved!

I’ve got a book with me about JavaScript and DHTML. But I will let that sit. As what I want now is to try and make PHP work for me here. I want it to switch stylesheets and a few other things. I want it to do it with something passed in GET or POST. I’ll try GET first.

I would also like to have PHP switch the page’s title.

I would say I would like it to switch meta tags too. But now I realize that that is silly. Meta tags are for search engines. I don’t think Google’s bots would follow my PHP.

Then I realize that I probably have screwed up something else here. I have one page and I ended up having accounts on two other unaffiliated free hosts. So I have backup pages.

I was concerned that Google was getting confused with this replication. So I fixed it so the meta tags come in via an SSI. The main site has real meta tags. The other sites have just a dummy comment.

Now I realize that this might not work. Google’s bots might get to see my site without it being executed. So it might be without the keywords.

Not sure what to do now. Anything I do to allow me to have files which are the same, but get different stuff SSIed, means that what Google sees is less than the full intact file I want it to see and index.

This use of keywords does seem to help get good results from Google in my experience. But now I am not getting that kind of service.

name=“keywords” content="…

A busy day but I am making progress!

Now I’ve got a .php page which can take a parameter on its web address, ?usr=, then one of two key words. Depending on which, it changes stylesheets!

Both style sheets are off other servers!

Now, these don’t both match the HTML. But I have something else set up already where they do match. Just change style sheets and one include for a picture and it matches something else.

Not actually tried calling this from inside another page yet.

PHP is like C, very much so.

I read much about using echo or print. I used echo and <<<END

Originally I tried IF ELSE on a constant, not even using a variable. But now I am using SWITCH on a string. But not a named variable, just what $_GET returns.

I have no paper documentation. Its all coming off the net.

So I am feeling good!

I am using a MacIntosh right now and I have little Mac experience.

This free web host does not let me edit my .ssi. It does not let me edit .shtml. I guess it does not understand them. It also does not take php in .shtml. I guess .htaccess would change that. But it does do php in .php.

It lets me edit .php but it conceals or hides the headers of the files in its editor. So such editin is useless. I don’t like this!!

So I have to edit on the MacIntosh and upload everytime. Not sure what to use to do this. I have used Dashcode. But it won’t let me open .php with Dashcode. So I have to keep it as .txt, then upload it, then change it to .php. Oh well!


So my problems seem to be solved. Now just a matter of doing all the work. I assume that PHP’s switch had an ‘else’ case.

What is the best PHP replacement for Server Side Include, include()?

If Google looks at my files, does it seem them before or after running Server Side Include or PHP? If it requests them like a web page I guess after? But my gut tells me no.

One host does allow full control of the permissions, like if you had a Unix login. They had it set so everyone could read and write. I have no idea why I would want this.

I assume that to show a web page it should be set to allow read. But if it has Server Side Include or PHP, then it must execute. Can I disallow read in such cases as execute is sufficient?

If I want to put something to keep programs from using the a form to contact, its best if I can hide my source code. Can I set it to execute but not read to get this?

No Extraneous Links is No Fun at All!

PHP’s to read emails?

The free web site hosts allow email accounts on the subdomain. Can I make a PHP which reads the email and then based on there being some key phrases, it takes the text and turns it into HTML for the web page?

I want someone to be able to update a news and announcements section.

Reading “Programming PHP”, by Ramus Lerdorf etal, O’Reilly.

O’Reilly books are always outstanding. They alone are reason enough to program computers.

They say to use include or require to include files. Where as Notenbaum uses readfile. They say you can supress display of warnings if you want with ‘@’.

The book talks about including headers and footers. But they might mean the header and footer portion of what displays on a web page. Not clear if they mean the html header, especially the meta tags and title.

Still not sure if Google will see those if I am getting them out of a php included file. Seemed like a page suffered when I made them included by SSI.

A big part of why I want big resources pages is to promote the links to Google for the other volunteer groups I run the pages for.

If I make these included I might lose this. If I let them be in the main .php file, but still subject to php flow control, then I am not sure how Google sees this.

Also I see that switch does have a default case. I need that.