Examples SSI

To get started on the reasons that prompted me to write this article: in the discussions members of the All-Russian Club of webmasters times there were disputes about whether it is better to use in case of repeating the markup (information) on a large number of pages - frames, JavaScript or SSI (Server Side Includes). My deep conviction is that frames should be used only where, without it really can not do, JavaScript (yes, and any other client scripts) too capricious and depend on your browser settings, so it can be used for advanced features only, but in no way to prostroeniya, for example, the navigation system. I will not foaming at the mouth to prove that technology SSI most abruptly mountains and eggs, but simply give the solution of common practical problems with the use of this technology.

(Immediately foresee outrage on the part of supporters of ASP and PHP technologies with the use of which is also possible to solve such problems, so for them: SSI technology is much simpler, with just a dozen operations, so no programming is a better choice, if only because that it can be mastered quickly)

last modification date of the document

A simple guideline:

  <-! # Echo var = "LAST_MODIFIED" -> 

Today's number in the proper format

If we want to display the date is not in the standard configuration of the software form, and what we need (for example, "Tuesday, May 30, 2000"), you can use the following construction: Preparation day of the week

  <-! # Config timefmt = "% u" ->
 <-! # Set var = "NUM_DAY" value = "$ DATE_LOCAL" ->
 <-! # If expr = "$ NUM_DAY = 1" ->
 <-! # Set var = "DAY" value = "Monday" ->
 <-! # Elif expr = "$ NUM_DAY = 2" ->
 <-! # Set var = "DAY" value = "Tuesday" ->
 <-! # Elif expr = "$ NUM_DAY = 3" ->
 <-! # Set var = "DAY" value = "medium" ->

 <-! # Elif expr = "$ NUM_DAY = 4" ->
 <-! # Set var = "DAY" value = "Thursday" ->
 <-! # Elif expr = "$ NUM_DAY = 5" ->
 <-! # Set var = "DAY" value = "Friday" ->
 <-! # Elif expr = "$ NUM_DAY = 6" ->
 <-! # Set var = "DAY" value = "Saturday" ->
 <-! # Else ->
 <-! # Set var = "DAY" value = "Sunday" ->
 <-! # Endif -> 

Preparation of

  <-! # Config timefmt = "% e" ->
 <-! # Set var = "DATE" value = "$ DATE_LOCAL" -> 

Get month name

  <-! # Config timefmt = "% m" ->
 <-! # Set var = "NUM_MONTH" value = "$ DATE_LOCAL" ->
 <-! # If expr = "$ NUM_MONTH = 01" ->
 <-! # Set var = "MONTH" value = "January" ->
 <-! # Elif expr = "$ NUM_MONTH = 02" ->

 <-! # Set var = "MONTH" value = "February" ->
 <-! # Elif expr = "$ NUM_MONTH = 03" ->
 <-! # Set var = "MONTH" value = "March" ->
 <-! # Elif expr = "$ NUM_MONTH = 04" ->
 <-! # Set var = "MONTH" value = "April" ->
 <-! # Elif expr = "$ NUM_MONTH = 05" ->
 <-! # Set var = "MONTH" value = "May" ->
 <-! # Elif expr = "$ NUM_MONTH = 06" ->
 <-! # Set var = "MONTH" value = "June" ->

 <-! # Elif expr = "$ NUM_MONTH = 07" ->
 <-! # Set var = "MONTH" value = "July" ->
 <-! # Elif expr = "$ NUM_MONTH = 08" ->
 <-! # Set var = "MONTH" value = "August" ->
 <-! # Elif expr = "$ NUM_MONTH = 09" ->
 <-! # Set var = "MONTH" value = "September" ->
 <-! # Elif expr = "$ NUM_MONTH = 10" ->
 <-! # Set var = "MONTH" value = "October" ->
 <-! # Elif expr = "$ NUM_MONTH = 11" ->

 <-! # Set var = "MONTH" value = "November" ->
 <-! # Else ->
 <-! # Set var = "MONTH" value = "December" ->
 <-! # Endif -> 

Production year

  <-! # Config timefmt = "% G" ->
 <-! # Set var = "YEAR" value = "$ DATE_LOCAL" -> 

Own conclusions resulting string

  <-! # Echo var = "DAY" ->,

 <-! # Echo var = "DATE" ->
 <-! # Echo var = "MONTH" ->,
 <-! # Echo var = "YEAR" ->

Format options for config timefmt necessary to look separately for each configuration web server. This example - FreeBSD, Apache. For more details see. Man timefmt
This design is used on the online store Web site Levingston.Ru

Date modified external file

Often on computer sites spread price list in MS Excel or Word format, and each time the hands prescribed date of its manufacture. With SSI is done like this:

  <a href=pricelst.doc> Price list </a>

 <-! # Config timefmt = "% d% m% y.." ->
 (MS Word 6.0 / 95, <-! # Flastmod virtual = "pricelst.doc" ->) 

This design is used on the company's Web site Duncan Service

Fighting <noframes>

Typically, the container writes "I'm sorry, but you should update your browser", the idea is there should be an alternative for users of older versions of browsers. Since the normal server information changes frequently, and the lazy webmaster every time to make changes in two places. With SSI problem is solved once and for all in a container <noframes> </ noframes> directive entered, insert the same file in which changes are made, or simply the navigation bar.

Fight with direct links to documents on a framed Web site

One of the arguments against the use of frame structures with the creation of web sites is the inconvenience of direct links to content files. For example, if the link from the search engines, or to a specific (non-root) document from another Web site, the user is taken to a page devoid of design or navigation elements that are usually placed in a separate navigation frame. With a straightforward design SSI can solve this problem. For this it is necessary to analyze where the user came (variable HTTP_REFERER) If he did not come with our server, and externally - to build a frame-based structure and substitute document requested by the user as a meaningful frame.

In the example below content.html file - this is the document, which is a direct link (for example, from a search engine), frame.html - the file in which the structure of frame construction. The QUERY_STRING value is substituted done in order to avoid infinite nesting frame structures.

content.html File

  <Html>
 <Head>
 ...
 <-! # Include virtual = "frame.html" ->
 </ Head>
 <Body>

 ...
 </ Body>
 </ Html> 

frame.html File

  <-! # If expr = "!! $ QUERY_STRING = done && $ HTTP_REFERER = / your_domain \ .ru /" ->
 <Frameset rows = "150, *">
 <Frame name = "NAVIGATION" src = "/ navigation.html">
 <Frame name = "CONTENT" src = "<-! # Echo var =" DOCUMENT_URI "-> done?">

 </ Frameset>
 <-! # Endif -> 

This design is used on the online store Web site Bolero

Print version of the page

Often there is an application problem - a beautiful multi-column design with the top and bottom caps, banners cloud, but when printing everything that does not need - extra paper, unnecessary information ... So you want to make a simple alternative view pages specifically for printing. To do this, it is sufficient to prepare two versions of the top and bottom caps, one --for screen display, the other - to print. As a switch between these options use a variable QUERY_STRING. Below are the basic structure for the page itself (file.html) for the top and bottom caps (top.html and bottom.html).

The structure of the page itself (file.html):

  <-! # Include virtual = "top.html $ QUERY_STRING?" ->
 here the body of the document
 <-! # Include virtual = "bottom.html $ QUERY_STRING?" -> 

Structure and top.html bottom.html

  <-! # If expr = "$ QUERY_STRING == / for_printing /" ->
 Hat Print
 <-! # Else ->
 cap for viewing
 <-! # Endif -> 

A link on each page must be of the form

  <a href=<"!--echo var="$DOCUMENT_URI" -->? for_printing
 > Printable version </a> 

This design is used on the Web site of All-Russian Club of webmasters

Fight with menu items

Suppose we have a few sections of a Web site that documents relating to the sections are in different directories. The task - to make sure that the navigation menu on these sections was lost (or is not illuminated, a different color, etc.) a reference to the section in which the user is currently. You can use variable DOCUMENT_URI.

  <-! # If expr = "! $ DOCUMENT_URI = / ^ \ / index.html /" ->
 <a href="/"> Home </a> <br>
 <-! # Endif ->

 <-! # If expr = "$ DOCUMENT_URI = / \ / about \ /index.html/!" ->
 <a href="/about/"> About </a> <br>
 <-! # Endif ->
 <-! # If expr = "$ DOCUMENT_URI = / \ / done \ /index.html/!" ->
 <a href="/done/"> Our work </a> <br>
 <-! # Endif ->

 <-! # If expr = "$ DOCUMENT_URI = / \ / partner \ /index.html/!" ->
 <a href="/partner/"> Our partners </a> <br>
 <-! # Endif ->
 <-! # If expr = "$ DOCUMENT_URI = / \ / client \ /index.html/!" ->
 <a href="/client/"> Our customers </a> <br>
 <-! # Endif ->

 <-! # If expr = "$ DOCUMENT_URI = / \ / price \ /index.html/!" ->
 <a href="/price/"> Our prices </a> <br>
 <-! # Endif ->
 <-! # If expr = "$ DOCUMENT_URI = / \ / contacts \ /index.html/!" ->
 <a href="/contacts/"> Our location </a> <br>
 <-! # Endif ->

 <-! # If expr = "$ DOCUMENT_URI = / \ / history \ /index.html/!" ->
 <a href="/history/"> Our history </a> <br>
 <-! # Endif ->
 <-! # If expr = "! $ DOCUMENT_URI = / \ / search.html /" ->
 <a href="/search.html"> Search </a> <br>
 <-! # Endif -> 

This design uses the company's Web site Web 2000

Contextual text output depending on the conditions

Suppose we have a task to change the appearance of the first node of the page, depending on where the user came from. The following construction is used to achieve this objective:

  <-! # If expr = "$ HTTP_REFERER = / www.zzz.ru /" ->
 Here are made the necessary actions
 <-! # Endif -> 

those. compared to the variable HTTP_REFERER

Fighting with different versions of the design for different browsers

Everyone knows that the browsers from different vendors and different versions show the same HTML-markup document from the special tags and attributes, and ending support for different versions of JavaScript. To make a Web site look okay for one version of the browser for the other, or not to fell JavaScript errors SSI means you can do a background check versions or browsers, and provide various options for HTML-markup. We analyzed the variable HTTP_USER_AGENT, which contains information about the type and manufacturer of your browser:

  <-! # If expr = "$ HTTP_USER_AGENT = / Mozilla \ / 4 / || $ HTTP_USER_AGENT = / Mozilla \ / 5 /" ->
 If the version of the browser is not a 4 or 5, then output option
 design, using, for example, DHTML
 <-! # Else ->
 There deduce simple design
 <-! # Endif ->

This design was used for the construction of frame structure and output of the internal menu (for Netscape - on DHTML, for MSIE - on ActiveX) Web site , "Om" magazine

Fight with registration of the results of scripts

The biggest problem with the script is that if there is a large amount of accumulated software - required when changing the design of their migration. Well, if the software is done correctly and the change does not apply to the display patterns of mathematics, however, and in such cases there are problems. For example, a search page would be a good idea to turn banners and ad networks, but not SSI directives are processed in the .cgi files. To solve such problems, you can use SSI as follows: no script to process mapping templates, and to cause the script of the HTML-document through SSI (unfortunately, so you can work with only those scripts that use the GET method - variable CONTENT_LENGTH not available in SSI) So how it is done there HTML-document, which is marked in the overall design style. It is inserted into Directive

  <-! # Include virtual = "/ cgi-bin / script.cgi $ QUERY_STRING?" -> 

In the first step, until QUERY_STRING is empty - the first step is called the script for the next steps of the script - the necessary parameters are passed. In the script three important lines:

  ...
 # Definition of addresses where to send data
 $ Query = $ ENV {QUERY_STRING};
 # Definition of the place from which the script was called
 $ Uri = $ ENV {DOCUMENT_URI};
 ...
 # Sending data on the same HTML-document from which the script was called
 print "<form action = $ uri method = get> \ n";
 ... 

This design is used in the section "Vote" for online supermarket Levingston.Ru

What can be done by using the Cookie and SSI

design in JavaScript often found that displays "Hello, Ivan Ivanovich!" when entering the web-site page. The same can be done with the help of SSI directive

  <-! # Echo var = "HTTP_COOKIE" -> 

Banners, caching and SSI

Sent Cyril Khlopov (NewTech)

As is known, banner systems offer include a code of some random variable in the URL display the script - from the cache protection.

  • You can generate a full-page script, from the first to the last character
  • You can do as advised help page banner systems - include by SSI script generyaschy random banner
  • Dynamic record of the document with the code banner JavaScrip-th

And you can still like this:

  <-! # Config timefmt = "% s" ->

 <-! # Set var = "RND" value = "$ DATE_LOCAL" ->
 <-! Russian LinkExchange code START ->
 <Iframe src = http:? //www.linkexchange.ru/cgi-bin/erle.cgi Some_id?
 <-! # Echo var = "RND" ->
 frameborder = 0 vspace = 0 hspace = 0 width = 468 height = 60 marginwidth = 0
  marginheight = 0 scrolling = no>
 <a href=http://www.linkexchange.ru/users/some_id/goto.map target=_top>
 <Img src = http:! //www.linkexchange.ru/cgi-bin/rle.cgi ?? <- # Echo var = "RND" ->
 alt = "RLE Banner Network" border = 0 height = 60 width = 468> </a>

 </ Iframe>
 <-! Russian LinkExchange code END -> 

That is, as a random variable will perform a number of seconds of 1970. Do not waste time and memory to run the generator script, Java-Script (among some users now it is fashionable) can be switched off. In my opinion quite rosy Smile happy
All of this has been tested and used by our administrator on www.j2.ru

A display pattern - different content

Uploaded by Evgeny Bespalchikov (KADIS)

Templates are often used in this way: <> There is only one file that describes the structure of the page, and the main contents include directive

  <-! # Include virtual = "$ QUERY_STRING.html" -> 
links, respectively, will be:
  href = "www.your_domain.ru/index.html?page1"
 href = "www.your_domain.ru/index.html?page2"
 ... 

The problem occurs if a user types the address directly http://www.your_domain.ru, ie QUERY_STRING = ""

Decision:

  <-! # If expr = "$ QUERY_STRING" ->
 <-! # Include virtual = "$ QUERY_STRING.html" ->
 <-! # Else ->
 <-! # Include virtual = "default.html" ->

 <-! # Endif -> 

where default.html - root page of the index (TOC) and a plug.