Server Side Includes is a simple way to insert the content of one file into other files.
Most include files are items such as a header, footer or navigation
that are repeated in many places on the site. Using SSI allows these items
to be stored in only one file as part of another file. So you would only need to change one file
and all other web pages would be updated.
Using Server Side Includes not only makes your source code more maintainable, but also more readable, as common elements are stored in a few files.
Most web servers are set up to run SSI, but in some web servers, Server Side Includes don't appear to work. You might need to save your file as .shtml rather than .html to make it work. The "s" is a parsing command. It will find server side include directives, and tell the server to parse the page. If your host does not support SSI, you might want to find a new host.
Here is SSI syntax:
<!--#directive parameter=value parameter=value -->SSI examples:
<!--#include file="header.html" -->Use this when the file that will be included is in the same directory, or the file is in a subdirectory of the directory.
<!--#include virtual="/path to file/header.html" -->
The above code will create an SSI that includes the text found in "header.html" file into the current page. The filename can be given relatively or absolutely. It is preferable to start at the root directory ( the first forward slash represents the server root or domain name ), so you can use the same code on every page that you want to include in that file.
The include files could be html, txt, inc or other type of files. Some web masters like to use txt files since they are smaller, they are handled by the server more rapidly.
If you are using a Unix server, you might want to consider using PHP includes. You can include files with .txt, .php, .html files and other extensions when you use a php include, but the file you are including into must be a php file. Most web servers are set up to run PHP SSI, but in some servers, You might need to enable CGI to run php files. CGI, short for Common Gateway Interface, is a standard for allowing scripts to be written by other languages to run over the Internet.
The syntax for a PHP include is:
<? include('/directory/file.php'); ?>
You can include content from a different website's URL if you use PHP includes, This is one of the advantages of PHP includes since the SSI I have mentioned before is not able to do that. So you can use it to share content across different web sites.
PHP includes uses include() and require() commands:
<? include('http://www.someothersite.com/directory/file.php'); ? >
or:
<? require('http://www.someothersite.com/directory/file.php'); ? >
The include() or require() functions are identical in every way. The difference between them is how they handle errors. The include() function generates a warning message but the program will continue execution. The require() function generates a fatal error and then stops execution. So using include() function can be faster than using require() function. The include function is used widely by PHP web masters.