Includes

Includes are a common thing for any website. Instead of having to rewrite the same code, all over again, it's much, much more simpler to just include a file with all that code already in there. Includes were made to make production of web pages easier! Take advantage of them! It's not too hard at all! But, before we get buckled down and started, there are two types of includes. SSI includes, and PHP includes. We're going to take a look at them and their differences, although ultimately, they still do the same thing!

SSI

SSI stands for Server Side Includes. These type of includes run on .shtml files. They do as they are told, and include the file easily. SSI, however is limited to only three functions; to include external files, to display date and times from the server, and to display file information.

PHP

PHP originally was an acronym for Personal Home Pages, but with the expansion of PHP, the acronym now stands for Hypertext Pre Processor. Because, changing a popular web design language's name, woudl confuse many people across the world. However, there are many types of PHP includes, and you don't have to learn PHP, and know it off by heart to be able to use them. All you need is a host that supports PHP. Unlike SSI, PHP offers many functions, and is quite a popular web programming language. All PHP scripts must be in files of a .php extension.

Comparison

While ultimately both do the same thing, there are many reasons why you might want to choose one over another. PHP offers many, many more functions than SSI, so you might choose PHP, PHP also offers shorter extensions. SSI offers an easy alternative, and if your host is Freewebs, you're definately going to be using it. I could keep on listing the differences between the two, but those are the only really major differences. If you have the time, and you'd prefer to look deeper into the matter, go Google them or whatever. Now, choose your type of include, and let's find out how to do them.

SSI Includes

First of all, you must find out if your host supports SSI. They might have the features they support on a page of theirs, or you might be able to contact them somehow. But, if you can't seem to be able to, simply open up a new page in whatever HTML editor you use, and copy/paste the following code.

Save it as a .shtml file, and upload it to your site. Then, using your favourite browser, go view the page. If you can see the current day's name, you're host supports SSI.

Now, the include. For an include to work, you'll need two files. The page which you want to include, and the page which is going to include the external page. On the page which is going to be included, you'd put whatever you want to include, be it a menu, or list of stylesheets. The choice is yours. With that page, save it as a .txt, and upload it to your server.

To include the file, open a new page, and set the page out as you normally would. When you want to include your file, place this code:

The <!--# denotes the SSI starting, followed by the vitual command. Next, you place the path where the SSI can find the file, which you want to include. The first forward slash ('/'), denotes the server root path. SSI will automatically include the domain name of your site before this.

If your using Freewebs, don't fret! They have set it up so SSI can run in .htm files. Now, save and upload the file to your website, then go view it in your browser. If the include seems to have worked, that's good, otherwise, you should try contacting your host.

PHP Includes

If you've decided to use PHP includes, and your host supports PHP, it's not too hard at all! Create a new file, and set it out as you normally would. When you reach the place where you would like include an external file, place the following code.

Obviously, replace "/directory/included.php" to the path of the file which you'd like to include. However, if all your pages aren't all in the same directory, you better use another type of include. This one is a bit more complicated, but definately worth it.

First of all, create a new file, and place the following code in it.

Save the file as .php, and upload it to your website, then view the page. It should have a lot of information on it. Find where it says "DOCUMENT_ROOT", and then copy and paste the path given.

This time, we're going to include the file differently. Using the code below.

Replace "DOCUMENT_ROOT" with the path you just copied. Then set the path to your file.

If nothing's working, contact your host, perhaps PHP isn't enabled.

Notes

You must keep in mind that SSI and PHP are both executed before being sent to the browser, that means, that you won't see the include code, instead you'll see the code on the file which you included. Nobody will be able to tell that you included that file!

If you're having trouble, contact me at nickyn001@gmail.com, or head over to the contact page, and contact me via those addresses there.