Home  >  Article  >  Web Front-end  >  STHML tutorial (1)

STHML tutorial (1)

巴扎黑
巴扎黑Original
2017-04-05 09:23:191820browse

What is SHTML

Using the html file extension of SSI (Server Side Include), SSI (Server Side Include), often called "server-side embedding" or "server-side include", is a server-based web page production technology similar to ASP.

How SSI works:

You can use Server-Side Include (SSI) directives to include text, graphics, or application information into a web page before the content is sent to the browser. For example, you can use SSI to include a time/date stamp, a copyright notice, or a form for customers to fill out and return. Using include files is an easy way to include text or graphics that appear repeatedly in multiple files. Just put the content into one include file instead of typing the content into all files. The include file is called with a very simple statement, which instructs the web server to insert the content into the appropriate web page. And, when you use include files, all changes to the content only need to be done in one place.

Because files containing SSI directives require special handling, all SSI files must be given the SSI file extension. The default extensions are .stm, .shtm, and .shtml.

The web server processes SSI commands while processing web pages. When the web server encounters an SSI directive, it directly inserts the contents of the containing file into the HTML web page. If the "include file" contains an SSI directive, this file is also inserted. In addition to the basic instructions for including a file, you can use SSI instructions to insert information about a file (such as its size) or to run an application or shell command.

A problem often encountered in website maintenance is that the structure of the website has been fixed, but a large number of web pages have to be redone in order to update a little content. SSI provides a simple and effective way to solve this problem. It places the basic structure of a website in several simple HTML files (templates). All we have to do in the future is to pass the text to the server and let the program Automatically generate web pages based on templates, making it easy to manage large websites.

Therefore, the purpose of pages using SHTML format is similar to ASP, but because it is an API, it runs faster and more efficiently. It is faster than ASP and slower than HTML. However, because server-side includes can be used, it makes page updates easier (especially Batch update banner, copyright, etc.), imagine that you have a piece of HTML, and you need to insert some special server-side scripts in the middle, such as inserting other HTML paragraphs. You choose ASP to complete this task, but if the task is more arduous, more work is needed. If it takes more time, such as 5 seconds, if you don't use ASP but use SHTML, the processing time may be only 4 seconds.

What is SSI used for?

The reason I bring up SSI is because Shtml - an acronym for Server-Parsed HTML. Contains HTML text containing embedded server-side include commands. The SHTML document is completely read, parsed, and modified by the server before being sent to the browser. There are some similarities between shtml and asp. In the file named shtml, some SSI instructions are used, just like the instructions in asp. You can write SSI instructions in the SHTML file. When the client accesses these shtml files, the server These SHTML files will be read and interpreted, and the SSI instructions contained in the SHTML files will be interpreted. For example: you can use SSI instructions in the SHTML file to reference other html files (#include). The file sent by the server to the client is Interpreted SHTML will not have SSI directives. It realizes functions that HTML does not have, that is, it can realize dynamic SHTML, which can be said to be an evolution of HTML. Sina's news system is like this. The news content is fixed, but the advertisements and menus on it are referenced using #include.

At present, there are mainly the following uses:

  1. Display server-side environment variables<#echo>

  2. Insert text content directly into the document<#include>

  3. Display WEB document related information<#flastmod #fsize> (such as file creation date/size, etc.)

  4. ##Directly execute the file on the server Various programs<#exec>(such as CGI or other executable programs)

  5. Set the SSI information display format<#config>(such as file creation date /Size display mode)

Advanced SSI can set variables using if conditional statements.

Use SSI

SSI is a set of commands provided for WEB servers. These commands only need to be directly embedded into the annotation content of the HTML document. like:

It is an SSI command. Its function is to copy the content of "info.htm" to the current page. When the visitor comes to browse, he will see the content of info.htm displayed in the same way as other HTML documents. The usage form of other SSI commands is basically the same as the example just now. It can be seen that SSI usage only requires inserting a little code, and the usage form is very simple. Of course, if the WEB server does not support SSI, it will just treat it as annotation information and skip the content directly; the browser will also ignore this information.

How do I configure SSI functionality on my WEB server?

On some WEB servers (such as IIS 4.0/SAMBAR 4.2), files containing #include directives must use an extension that has been mapped to the SSI interpreter; otherwise, the Web server will not process the SSI directive; by default, the extension The names .stm, .shtm, and .shtml are mapped to the interpreter (Ssinc.dll).
Apache depends on your settings. Modify srm.conf such as:

AddType text/x-server-parsed-html .shtml will only parse SSI commands for files with .shtml extension
AddType text/x-server-parsed-html .html will parse SSI instructions for all HTML documents

The Netscape WEB server directly uses the Administration Server to turn on the SSI function.
Website uses the Mapping tag in the Server Admin program, and the extension added content type is: wwwserver/html-ssi
The Cern server does not support SSI. You can use the SSI fraud method. Go to http://sw.cse.bris.ac.uk/WebTools/fakessi.html and download a PERL script to make your CERN server use some SSI commands. (The exec command is not supported.)

The above is the detailed content of STHML tutorial (1). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn