Home Login Registration Authors Contact Us About Us Subscribe
Want to receive new articles via e-mail? Click here!
: Home  :: Web Design  :: Design Tips
Learning SSI - Include Me In!
by Webdevinfo - Webmaster
Views: 737
Votes: 1
Rating: 0.00
Rate this article  Print this article  Email this article  View this article in PDF  Discuss this article
First< Prev | Page:  1 | 2 | 
The Article

Create a Working Example - Part II

OK, so now we have our four page site setup. But what if we wanted to add a new page called Links? Normally this would mean that we would have to edit all four pages to add a link to our new page. Not with SSI.

Simply create a new page and save it as links.shtml with the following code:

<html>
<head>
<title>My Website!</title>
</head>
<body>
<table width="100%" bgcolor="#808080" border="0" cellpadding="18" cellspacing="1">
 <tr bgcolor="#ffffff">
  <td width="140" bgcolor="#d0d9e6">
  <!--#include file="menu.html"-->
  </td>
  <td width="*" bgcolor="#ffffff" valign="top">
  <h1>My Links!</h1>
  </td>
 </tr>
</table>
</body>
</html>

Once that is done we then need to edit our menu.html page and add a link to the new Links page like so:

<ul>
<li><a href="index.shtml">Home</a></li>
<li><a href="about.shtml">About Me</a></li>
<li><a href="photos.shtml">Photos</a></li>
<li><a href="contact.shtml">Contact Me</a></li>
<li><a href="links.shtml">Links</a></li>
</ul>

But what if the include file is in another directory on your server?
If you want to include a file located inside a different folder on your server you will need to change the include statement slightly. Instead of using:

<!--#include file="menu.html"-->

You use:

<!--#include virtual="full_path_to_include/menu.html"-->

You then need to set the full path to the include file in the statement.

What file types can I include?
In this working example we have been working with including a .html file, but this is not the only type of file you are able to include. Other file types that can be used are:

  • .inc
  • .txt
  • .htm

The reason I choose .html files for inclusion is because, if by accident your visitor is directed to the include file on it's own, it will still be shown with the proper HTML formatting. Which you choose to include is completely up to you.

And that's it.

Simple huh? Now whenever you want to add a new page to your site you only need to edit one file and your menu is updated on all pages throughout your site.

Built in SSI statements

As well as being able to include other files inside your pages, Apache also has built-in statements which can be included in the .shtml pages.

Below is a list of some of the most commonly used built-in statements that you can use on your site:

  • DOCUMENT_NAME - Displays the complete path of the current document.
  • DOCUMENT_URI - Displays the local path of the current document from the base directory of the webspace.
  • DATE_LOCAL - Displays the current local date & time.
  • DATE_GMT - Displays the current Greenwich Mean Time date & time.
  • LAST_MODIFIED - Displays the date & time of the last modification of the current document.
  • REMOTE_ADDR - Displays the IP address of the remote client browser.
  • SCRIPT_NAME - Displays the virtual path of the script being executed.
  • REMOTE_HOST - Displays the host name of the remote client.
  • HTTP_USER_AGENT - Displays the name of the remote client browser software.
  • REFERER - Displays the URL of the HTML document which referred the remote client to this document.
  • SERVER_NAME - Displays the computer name of the HTTP server.
  • SCRIPT_NAME - Displays the virtual path of the script being executed.
  • REMOTE_USER - Displays the user name used to validate authentication from the remote client.

However, in order to include these built-in statements you do not use the same format as previously shown:

<!--#include file="menu.html"-->

Instead you need to use the following format:

<!--#echo var="BUILT_IN_STATEMENT"-->

Simply replace the part that reads BUILT_IN_STATEMENT with the statement of your choice.

You can also include CGI scripts in your pages too. To do this you use the format:

<!--#exec cgi="/cgi-bin/script.cgi"-->

And there you have it. SSI in a nutshell!

Before I finish up though, I need to tell you that there is one small drawback to using SSI. Using SSI can slow down the speed of the page loading in your visitors browser. This is because the server needs to parse the info from the included file into the other pages as they are being called. This usually takes only a split second for the server to do, but if you start calling multiple includes in your page it will take longer for your server to parse them all. So, providing you don't call too many includes in each file the Pros of SSI far outweight the Cons.

Conclusion

Hopefully you now have a good understanding of how SSI works, how to use them on your site, and what built-in statements you can use.

Best of luck using SSI in the future and if you have any questions, feel free to ask the members of the Community Help Forums.

First< Prev | Page:  1 | 2 | 
Rate this article  Print this article  Email this article  View this article in PDF  Discuss this article
Similar/related articles:
Advanced Search
Site Search:


FirstWebHosting
Top Ten Hosts as picked by our editors - with reviews and interviews.
The Host Planet
Web hosting reviews and ratings. Learn how to spot a great host.
Hosts2002
The first and greatest hosting directory with the consumer in mind.
Hostcue.com
Hosting directory for the masses with special offers Check us out!
WebDevForums
Web developers or all levels discuss the details of design and ecommerce.
Needscripts.com
Free scripts and applications for web developers.