Is there a simple way to include a file for things like headers or footers that might be common to a bunch of pages in a site, without necessarily using PHP to do so? I kind of figure it is, but I’m not really sure of what exactly I should be searching for as far as docs/tutorials.
DHTML (this means Javascript) will not work unless the device runs Javascript. Not all user agents run Javascript.
But ASP and PHP are back-end languages/environments so they will send the same data to all user agents.
You need a server side language. I did some research on this before. CSS does not allow you to do this, and even though you can use an iFrame, it’s not really the most recommended tool. So in terms of standards you’re prefered to use a server side language, or alternatively you can use a CMS which does this all for you.
Doing this manually is horrible, trust me. I did it once on a site and it soon became unmanageable. How big is the site your proposing? The reason I am asking is because if it’s anything between 6 - 20 pages prefer not to use server-side includes, because it’s not worth it. Well, was not for me anyhow.
Normally, I would just use PHP for my own purposes. The reason I asked was I had been talking with a friend who had done a fairly basic website for a volunteer organization that he is a member of. While the webhost provider may (probably) have PHP and other popular scripting options available, this person only does the occasional web site of probably less than a half-dozen pages and really doesn’t want to learn any scripting language at this point. Heck, I’m still trying to convince him that CSS might save some time and grief
As a result, I was trying to recall how to go about consolidating some of the data that is the same from page to page into separate files for headers, footers, and menus. Probably overkill for such small sites, but I thought it might of use to him anyways.
Dan Schulz had a really good breakdown on another forum (he may have also posted it over here somewhere too) about using really simple Server-Side Includes… yeah, they used PHP but not much, no logic really just a lot of echos.
I think it was about as bare-bones as you could get. Did you find something similar or do you want me to try to dig that up for you?
On the other forum I think he might have even had a link to that thread in his sig.
Ignore the links in the posts…looks like the forum takes random seo-sleazewords and links them to random, unimportant stuff.
I’ve never used includes so I can’t personally vouch for any of this but it’s from Dan so unless something’s changed in the world of includes since this thread, I’d say this probably does it.
I would read the whole thread, too. People ask a lot of questions and a small mention of security comes up.
Interesting… I already understood the issue about the include files possibly being served up as plain text - which was why I thought the current vogue was to put includes in a directory above public_html or www… one that the index file can request from, but one that cannot be directly requested via a client browser? Or is that a more recent development since that thread (2007/2008)?
What I wrote on another thread recently, for a very brief summary:
To use server-side includes (SSI), save the code that you want repeated on each page as an HTML fragment - ie, save it as a .htm file, just as it is, don’t include all the doctype, head and body tags. Then on each page, you need something like:
<!–#include virtual=“/menu.htm” –>
You can use root or relative links, but you can only include files on the same domain.
You then need to save your main files as .shtml or instruct the server to treat all .htm/.html files as shtml.