Target versus Include Part 2 - Include
In this simplistic illustration of this use of frames, we do not really need the target function, but rather the include function. If the menu was made into an include file, then it can be inserted in each page, rather easily and very simply, and would achieve the same goals and results that the frames were expected to deliver.
This can be done very simply by using the include directive/function of sever-side scripting, using SSI or PHP. To illustrate this, lets say that, we made a file left.txt, that contains everything you wanted to appear on the left panel (the menu, logo, etc.). This file can be inserted into every page by including the following short codes:
-
SSI - Server Side Includes
<!---#include virtual="left.txt" --> -
PHP - Hypertext Preprocessor
<?php include 'left.txt' ?>
Both are simple to implement, and produces the same result. The choice really depends on what your server supports. If it is only one, then the decision is made for you. If you have both options, I would venture to offer the following suggestions:
- If you do intend to use PHP for other purposes also in your pages, in the foreseeable future, start using the PHP option. Not that only that it will be your entry to the world of PHP, but it will also be consistent with the PHP files you may start creating in the future.
- If you do not intend to use PHP for other purposes also in your pages at all, then stick to SSI option, to keep it simple.
- If you are already using PHP, obviously you do not need my suggestion, and you may even teach me a trick or two.
Please note that:
When using the SSI option, you do not have to change the file extension of the main file (i.e. the file that contains the included pages); .htm or .html extensions are perfectly acceptable. But, when you are using the PHP extension, it would be advisable to use .php extension.
However, with either option, it is highly recommended that you first check the instructions provided by your server and/or consult with their support team, to assure a smooth implementation.
Side Notes:
- The included files differ from the actual html files radically in the sense that the included files needs to stripped of html, title, head, body, etc. tags, and represent only the content materials, since these tags are already part of the main page it is inserted into. In other words, the included files should contain only the content you would place between <body> and <body> tags, nothing else!
- The above illustration uses .txt file extension for the included files. To the best of my knowledge, and for all practical purposes, the file extension does not may any difference. I seem to favor .inc extension, for obvious reasons.
Relative Paths
The above illustration of including files using SSI and PHP is based on the assumption that both the including and the included files are in the same directory.
However, when multiple directories are involved, the use of relative paths requires futher considerations.
Relative to Current Directory:
- This method uses ../ to go up the directory tree structure for each level.
- For example, if the included file (i.e. left.txt) is in the root directory, and the including file file is in a child directory , then the relative path would be ../left.txt.
- This method of defining relative paths works with both SSI and PHP.
Relative to URL:
- This method sets the path relative to the root directory.
- For example, if the included file (i.e. left.txt) is in the root directory, and the including file is in a child directory, the the relative path would be /left.txt.
-
This method of defining relative paths works with SSI but with certain further considerations depending on the version of Apache on the server.
- Apache 2:
The relative path /left.txt will be valid from any where in directory structure, except from the root directory. In the root directory the relative path would be left.txt. - Apache 2.2:
The relative path /left.txt will be valid from any where in directory structure, including the root directory. In other words, from the root directory both /left.txt and left.txt would be valid.
- Apache 2:
- This method of defining relative paths does not work with PHP.
Next Step
Now that we have identified the include function and seperated it from the target function, we can address the latter in Part 3 of this article.
- Feed-back & Comments:
- Please send any comments, opinions, and even contributions on this subject, using the Feed-Back Form.
- Further Reading:
- You can review the list of Related Articles, with brief descriptions and links on the Auxiliary Panel,










