Server Side Includes (SSI) Is A Very Useful Tool For Webmasters
|Why Choose Singapore Web Hosting .com
With thousands of website hosting companies why choose our service? Because we care about every customer and every detail of our business. We provide Unix / Linux web hosting, Windows hosting, email hosting, dedicated servers, domain name registration, web design and promotion services. And we make sure the job is always done right.
What Can Server Side Includes (SSI) Do For You?
You may have noticed as you browse this site, that our pages end with shtml extension instead of the more familiar html or htm. This is because we use Server Side Includes (SSI for short). Used properly, SSI can help make your web site more responsive and can even help make maintaining your site a much easier task.
Simply put, SSI directives in a shtml page will call another file (which can be text file or a program) and merger (include) the result in the finished page sent to browser. In other words, SSI will include or copy files into a web page. Think of it as being sort of like a document merge in word processing.
An example will make it clearer.
Take a look at the top menu on this page. In the actual source shtml code, there's no visible text at that place. Instead, I use this line of SSI command:
<!--#include file="header.txt" -->
In the header.txt file, which is a simple unformatted text file created by Notepad, I write these html code just like in any other normal html pages:
When your browser requested this page, our server first parsed the shtml file, then processed the SSI directive line (called the header.txt file), merged what's in header.txt into the final page, then sent it to your browser. So, instead of seeing the SSI directive, you see a normal top menu retrieved from the header.txt
But if you "view source" of this page, you won't see the SSI directive at all since the server has processed it before sending it to you.
Now look at the menu at left side, at the bottom, even the newsletter subscription form, they're all created by SSI. The reason? It makes web site maintenance much easier.
SSI can do much more than that. Here're some examples.
Display Local Time With Server Side Includes
The ECHO directive allows you to include information from the environment in your pages. For example, date and time.
This is something that you have probably seen on quite a few pages:
This offer is going to be expired at midnight of
Thursday May 13 2021
You don't think the webmaster is updating the page everyday, do you;-)?
The following little snippet of source code is all you need to add this feature to your page:
This offer is going to be expired at midnight of <b><!--#config timefmt="%A %B %d %Y" --> <!--#echo var="DATE_LOCAL" --></b>.
The ECHO directive DATE_LOCAL displays the local time of where your server is. The CONFIG command adjusts the time format.
Similarly, DATE_GMT will show Greenwich time.
Making A Real Back Button
Here is a cute server side includes trick, a back button that actually takes you back to where you came from.
BACK BUTTON (Remember to press forward and come back here;-)!
How did the page know where you came from. Remember, SSI can bring in server environment information and one tidbit at our disposal is HTTP_REFERER. This is the URL that brought you to this page. Here is the source code for this trick:
<A HREF="<!--#echo var="HTTP_REFERER"-->">BACK BUTTON</A>
If you came to this page directly such as from bookmark, then (none) would be the value for HTTP_REFERER.
Here are some of other values ECHO directive can use:
CONTENT_LENGTH - size of input posted from client
You're visiting this page from IP 188.8.131.52 , right?
Another great thing about server side includes is the ability to either run programs as straight system executions, or as CGI Scripts. For security reasons, only use them if you know what you're doing.
As you can see, SSI is a very useful tools for webmasters. However, sometimes you may need to take another thing into consideration - performance. When a regular HTML page is requested, the server only has to handle sending that page to the browser requesting it. With SSI, the server must first read the SHTML file, process any directives (which can be program output or files to be included in) and then deliver the assembled page to the browser.
If you are expecting thousands of hits per minute, that can be a lot of extra work for the server. On the other hand, keeping your pages trim will more than make up for the SSI performance cost in most cases.
Today, horsepower is cheap and getting cheaper. If your hosting service provider does not allow SSI because it may slowdown their server significantly, you can be sure they're not that trustworthy.
Feel free to use this article
in your publication or web site.
Web Hosting Articles and Tips
Why Do You Need A Web Site In The First Place?
Web Design Articles and Tips
Web Site Design Basics - From Internet Marketers
Web Promotion, Internet Marketing Articles and Tips
Can You Still Make Money On The Internet?
Web Hosting Singapore | Web Hosting | Email Hosting | Domain Registration | Web Design | SEO | Resellers Plan | Dedicated Servers
Copyright © 2001-2009 Singapore Web Hosting .com Web Services Division of Silver Media