Beginning users can mainly use SSI technology for two purposes: to “glue together” a page from parts of html code and to run scripts in order to place the results of their work on the created html page. In the first case, the corresponding files are read from the server disk and inserted into the code of the page from which the SSI code was called. In the second case, the web server, having found the SSI instruction, runs the script located on the disk and inserts the result of the script into the final page.

Let's take a closer look:

  • “Gluing together” a page from parts of html code.It is used to avoid duplicating the same HTML code in multiple web pages. For example, you can include the entire design in SSI inclusions, which are included in a specific html file, which will contain only the text of a specific page.

    Let’s place the “header” of the web page (design elements, menus, necessary links and other elements that are present on all pages) in the header.inc file, and place the bottom of the web page (the final part of the design) in the footer.inc file. Next, let's create a file called index.shtml, which will look like this:

    <!--#include file="header.inc"-->

    And here we will have the main text of the page
    <!--#include file="footer.inc"-->;

    It is assumed that we have placed html code in the inclusion files, at least like the start/end tags <html>, <head>, <body> and so on. As a result, the user will receive a page that will first include the contents of the header.inc file, then the words “And here we will have the main text of the page” and then the contents of the footer.inc file.

    This use of SSI is convenient from the point of view of not having to constantly insert the same html code into newly created pages, and also from the point of view of the convenience of changing the main elements of the site - we change the html code in one place, which immediately changes on all pages according to throughout the site.

  • Running scripts and placing the results of their work on the created html page. In this way, you can place on the page almost any functionality that can be written in the perl language, for example (or in almost any other hosting supported.

For example, you have a script counter that shows how many visitors visited your page and it is located at /cgi-bin/count.pl. Let's include the result of his work in a web page. To do this, we will place the following SSI code in the code of the html page:

<!--#include virtual="/cgi-bin/count.pl"-->

As a result, the counter that the script displayed will be placed on the page that the user sees /cgi-bin/count.pl.


Diagnosis of errors during use SSI

If, when using SSI commands on your html pages, you see the message “[anerror occurred while processing this directive]”, this indicates that an error occurred while processing the SSI instruction by the web server.

Possible reasons for this error:

  • the path to the included file/script is set incorrectly - such a file does not exist
  • The cgi script you are trying to insert into the page is not working correctly
  • the tariff at which your server operates does not allow the use of CGI script execution
Ha estat útil la resposta? 27 Els usuaris han Trobat Això Útil (88 Vots)