How does SSI work and what is it used for


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


Let's take a closer look:




  • "Gluing" a page from parts of html code. It is used in order not to duplicate the same html code in many web pages. For example, you can put the entire design in SSI inclusions, which are connected in a specific html file, which will contain only the text of a specific page.


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



    And here we will have the main text of the page
    ;

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


    This use of SSI is convenient from the point of view of not having to insert the same html code into newly created pages all the time, as well as 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 throughout the site.




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


    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 html page code:



    As a result, a counter will be placed on the page that the user will see, which brought out the script /cgi-bin/count.pl .



    Error diagnostics when using SSI

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


    Possible causes of such an error:



  • the path to the included file/script is set incorrectly — such a file does not exist

  • the cgi script that you are trying to insert into the page is not working correctly

  • the tariff that your server uses does not allow you to use the execution of cgi scripts