In this installment of my ongoing "Why I Did It" series, I'm going to continue discussing the use of includes, focusing on PHP and Server Side Includes (SSI) for fast and easy page formatting, and simplified site maintenance.
The first part of this article laid the groundwork for today's discussion by outlining what "includes" are, and some of the things that they're used for. I also showed you the syntax for using includes with Microsoft's popular "FrontPage" visual HTML Editor and site maintenance tool. But what about those Webmaster's who do not use FrontPage? Can they use includes to perform routine maintenance tasks and so much more?
PHP is not yet something that might be considered "standard"...
In most cases, the answer is yes, they can! While other options may be available, two that I have (and do) use are PHP and Server Side Includes (SSI), and we'll take a look at them today:
PHP Includes
As I said in my first installment, I'm not a programmer, and so I can't explain to you WHY PHP includes are preferable to standard Server Side Includes (SSI), even though I have found several benefits to using them over SSI. In fact, there are only two things that I know about PHP: I need to name my pages ".php" and that PHP really stands for "Personal Home Page" — NOT the often claimed "Hypertext Pre-Processor" — a function-describing name given to it by marketing types who couldn't sit in some corporate boardroom and sell the use of a powerful technology with the words "Personal" or "Home Page" in it. Evolution, you know, but I digress:
PHP is a server-side technology that requires a PHP enabled Web server. While increasingly available to Webmasters using virtual hosts, and easily installed by those on dedicated boxes, PHP is not yet something that might be considered "standard," and so if you're not sure that your host supports it, you should inquire first before frustrating yourself over something that may not currently work for you.
If you do have a PHP enabled server, then you are definitely in luck! I say this because one of the coolest things that I have found about the way PHP works for me on my box, as opposed to what works for me using SSI, is that I am able to include "outside" pages into my content. By that I mean I can by using the full, absolute URL of the resource that I desire, toss it into my Web page, even if it is on a different server.
This was something that I was unable to do with SSI, which on my hosts' setup, didn't allow me to pull content from other domains, or include CGI script output, for example. These capabilities are extremely important for me, as they allow me to include the same "Pic Of The Day" (POTD) panel on all of my sites, or the same Full Page Ad (FPA), or anything else that I desired! This is a key prerequisite for my content centralization strategy where many "front ends" can share the same content-filled "back end" — a process much simplified by PHP's relativly easy integration with mySQL databases, a topic beyond the scope of this article. For now, basic file sharing in PHP is possible through this simple snippet of code:
?PHP include("https://domain.com/header.php"); ?
In this example, I would use this include at the top of my page, calling a standard page header file to appear, and in this case I would also likely have another include at the bottom of my page to display the footer file:
?PHP include("https://domain.com/footer.php"); ?
This is a great way to include navigational structures , credits, copyright, contact and legal info across all of your pages, in a way that is easily updated by editing a single file. You can find a wealth of additional PHP information and tutorials at the official Web site: https://www.php.net Once my domains were moved to upgraded Linux servers with PHP support I abandoned the use of SSI in favor of the more flexible PHP approach.
Server Side Includes (SSI)
Perhaps more accessible to a wider range of Webmasters is SSI. While in my own experience, its use has not been as flexible as that of PHP, I relied upon it to include page headers and footers, along with BODY tag information across one of my sites that wasn't yet PHP enabled. I found that using SSI includes for such things as BODYtag inclusion is an easy way to change the look and feel of your site by updating one file with new background colors or images, and text and hyperlink properties.
When using SSI on my virtually hosted domains, I was required to adopt the ".shtml" extension on the pages I had placed the includes before they would work. My host (apparently for security reasons) disallowed the use of SSI (#exec) from within CGI scripts, and CGI output from within SSI. Major inconveniences for me given the amount of CGI used on the same site that I placed these includes. Still, the benefits outweighed the restrictions, and I was able to use the following snippet format to add my various includes:
!--#include virtual="/includes/header.shtml" --
One problem that I encountered with this was my excessive use of this happy new tool: I used includes for the HEAD and BODYtags, to provide common headers, footers, navigation, and certain JavaScript based advertising functions, and anything else that I could think of, with an end result of pages that would not fully load on occasion, probably as I was choking my server... A poor trade for the flexibility and ease of maintenance that I was seeking. Once my domains were moved to upgraded Linux servers with PHP support I abandoned the use of SSI in favor of the more flexible PHP approach.
In my next installment, I'll discuss JavaScript "includes" and the damn Walnut metaphor... ~ Stephen