What is SHTML
HTML file extension using SSI (Server Side Include), SSI (Server Side Include), usually called "server side
embedding" or "server side include", is a similar ASP server-based web page production technology.
How SSI works:
You can use the Server-Side Include (SSI) directive to include text, graphics, or application information into a web page
before sending the content 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 an include file is an easy way to use an include file for text or graphics that repeat
in multiple files. Just put the content into an include file instead of having to import it 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
and, when using 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 command, it directly inserts the content of the included file into the HTML web page. If the "include file" contains an SSI directive, this file is also inserted. In addition to the basic
directives for including files, you can also use the SSI directive to insert information about the file (such as the size of the file) or to run applications or shell commands.
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 puts the basic structure of a website into several simple HTML files (
templates). In the future, all we have to do is to Pass it to the server and let the program automatically generate web pages according to the template, making it
easy to manage large websites.
So, 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, but because server-side inclusion can be used, it can be used Page updates are easy (especially batch updates of banners, copyrights, etc.). Imagine
that you have a piece of HTML and you want 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 and requires more time, such as 5 s, then you do not need ASP but use SHTML.
Maybe the processing time will only take 4s.
What is SSI used for?
The reason why we mention SSI is because Shtml - the acronym of Server-Parsed HTML. Contains HTML text containing the
command on the embedded server side. The SHTML document is completely read, analyzed, and modified by the server before being sent to the browser. shtml
is somewhat similar to asp. The file named shtml uses some SSI instructions, just like the instructions in asp. You can write SSI instructions in the SHTML file
. When the client accesses these shtml files, the server will read and interpret these SHTML files, and interpret the SSI instructions contained in the SHTML files. 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 already interpreted SHTML and will not have SSI instructions. It realizes functions that HTML does not have, that is, it can realize
dynamic SHTML. It 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 are referenced using #include.
Currently, there are mainly the following uses:
Display server-side environment variables<#echo>
Insert text content directly into the document<#include>
Display information related to WEB documents <#flastmod #fsize> (such as file creation date/size, etc.)
Directly execute various programs on the server<#exec> (such as CGI or other executable programs)
Set SSI information display format< ;#config> (such as file creation date/size display method)
Advanced SSI
Using SSI
SSI is a set of commands provided for the WEB server. These commands can be directly embedded into the comment content of the HTML document. For example:
is an SSI instruction, its function is to copy the content of "info.htm" to the current page. When visitors come to browse, they will see the content of info.htm displayed in other
HTML documents. The usage form of other SSI commands is basically the same as the example just now. It can be seen that the use of SSI 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 to configure SSI function 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
program; otherwise, the Web server will not process the SSI directive ;By default, the extensions .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 instructions for files with .shtml extension
AddType text/x-server-parsed-html .html will parse SSI instructions for all HTML documents
Netscape WEB server can directly use 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
Cern server does not support SSI, you can use the SSI fraud method, go to http://sw.cse.bris. Download
a PERL script from ac.uk/WebTools/fakessi.html to make your CERN server use some SSI commands. (The exec command is not supported.)
Basic format of SSI command
Program code:
Note:
is a comment in HTML syntax. When the WEB server does not support SSI, this information will be ignored.
#include is one of the SSI instructions.
file is the parameter of include, info.htm is the parameter value, which in this command refers to the name of the document to be included.
Note:
Example:
This Document name
Current time
Your IP address
# include Demonstration
Function: Insert the content of the text file directly into the document page.
Syntax:
<--#include file="File name"-->
file file name is a relative path relative to the directory containing the document using the #include directive. The included file can be in the same
level directory or its subdirectory, but not in the upper level directory. If it represents the nav_head.htm document in the current directory, it is
file="nav_head.htm".
The virtual filename is the full path to the virtual directory on the Web site. For example, it means relative to the
nav_head.htm file in the hoyi directory under the server document root directory; then it is file="/hoyi/nav_head.htm"
parameter:
file specifies the included file relative to this document Location
virtual specifies the location relative to the server document root directory
Note:
The file name must have an extension.
The included file can have any file extension. I think it is most convenient to use the htm extension directly. Microsoft recommends using the .inc extension
(it depends on your preference).
Example:
Insert the header file into the current page
Insert the tail file into the current page
#flastmod and #fsize Demonstration
Function:
#flastmod The last update date of the file
#fsize The length of the file
Syntax:
Parameters:
file specifies the included file relative The location of this document, such as info.txt, represents the info.txt document in the current directory
virtual specifies the location relative to the server document root directory, such as /hoyi/info.txt, represents
Note: the file name must contain extension.
Example:
Insert the latest update date of the news.htm file in the current directory into the current page
Insert the file size of news.htm in the current directory into the current page
#exec Demonstration
Function: Insert the output of an external program into the page . Can be inserted into CGI programs or as input to regular applications, depending on whether the
parameter used is cmd or cgi.
Syntax:
Parameters:
cmd Regular Application
cgi CGI Script Program
Example:
The password file will be displayed
will display the file list in the current directory
will execute the CGI program access_log.cgi.
Note: As you can see from the above example, this command is quite convenient, but it also has security issues.
Prohibition method:
Apache, delete the "Options Includes ExecCGI" line in access.conf;
In IIS, to disable the #exec command, you can modify the SSIExecDisable metabase;
# config
Function: Specify the format of error information, date and file size returned to the client browser.
Syntax:
Parameters:
errmsg Customize SSI execution error message in any way you like.
sizefmt file size display mode, the default is bytes mode ("bytes") and can be changed to kilobyte mode ("abbrev")
timefmt time display mode, the most flexible configuration attribute.
Example: Display the size of a non-existent file
< ;!--#fsize file="non-existing file.htm"-->
Display file size in kilobytes
Syntax:
Display time in a specific time format
Display today’s day of the week, month, and time zone
XSSI
XSSI (Extended SSI) is a set of advanced SSI commands, built-in In the mod-include module of Apache 1.2 or higher. The commands that can be
used are:
#printenv
#set
#if
#printenv
Function: Displays all environment variables currently existing in the WEB server environment.
Syntax:
#set
Function: You can assign values to variables for use in subsequent if statements.
Syntax:
Example:
#if
Function: Create a page that can change data. The data is displayed according to the requirements calculated when using the if statement.
Syntax:
Display content
Display content
Display content
Welcome to Hoyi CGI Factory’s branch in Zibo Hotline Website http://hoyi.zb169.net.
Welcome to Hoyi CGI Factory At *'s branch http://linux.cqi.com.cn/~hoyi.
Welcome to Hoyi CGI Factory! --#endif"-->
Note: The backslash used in the previous directive is used to replace the inner quotes so that they are not interpreted as terminating the expression. Cannot be omitted.
1. Config command
Config command is mainly used to modify the default settings of SSI. Among them:
Errmsg: Set the default error message. In order to return the user-set error message normally, the Errmsg parameter must be placed
in front of other SSI commands in the HTML file. Otherwise, the client can only display the default error message instead of the one set by the user. Custom information.
Timefmt: Define the format used for date and time. The Timefmt parameter must be used before the echo command.
The displayed result is:
Wednesday, April 12, 2000
Perhaps the user is unfamiliar with the %A %B %d used in the above example. Below we will summarize some of the more commonly used ones in SSI in the form of a table.
Date and time format.
Sizefmt: Determines whether the file size is expressed in bytes, kilobytes or megabytes. If in bytes, the parameter value is "bytes";
Abbreviations may be used for kilobytes and megabytes. Similarly, the sizefmt parameter must be placed in front of the fsize command to be used.
2. Include command
The Include command can insert text or pictures from other documents into the currently parsed document, which is the key to the entire SSI. Through the
Include command, you only need to change one file to update the entire site instantly! The
Include command has two different parameters:
Virtual: gives the virtual path to a document on the server side.
File: Gives the relative path to the current directory, where "../" cannot be used, and absolute paths cannot be used.
This requires each The directory contains a header.html file.
3. Echo command
Echo command can display the following environment variables:
DOCUMENT_NAME: Display the name of the current document.
DOCUMENT_URI: Displays the virtual path of the current document. For example:
With the continuous development of the website, Those increasingly long URL addresses are sure to cause headaches. If you use SSI, everything will be solved. Because we
can combine the domain name of the website and the SSI command to display the complete URL, namely:
http://YourDomain
QUERY_STRING_UNESCAPED: Displays the query string sent by the client without escaping, in which all special characters are preceded by the escape character "". For example:
DATE_LOCAL: Displays the date and time in the server's set time zone. Users can combine the timefmt parameter of the config command to customize the output information
. For example:
The displayed result is:
Saturday, the 15 of April, in the year 2000
DATE_GMT: The function is the same as DATE_LOCAL, except that the date is returned based on Greenwich Mean Time. For example:
LAST_MODIFIED: Displays the last update time of the current document. Similarly, this is a very practical function in SSI. As long as you add the following simple text
to the HTML document, the update time can be displayed dynamically on the page.
CGI environment variables
In addition to SSI environment variables, the echo command can also display the following CGI environment variables:
SERVER_SOFTWARE: Displays the name and version of the server software. For example:
SERVER_NAME: Displays the host name, DNS alias or IP address of the server. For example:
SERVER_PROTOCOL: Displays the protocol name and version used by the client request, such as HTTP/1.0. For example:
SERVER_PORT: Displays the server's response port. For example:
REQUEST_METHOD: Displays the client's document request method, including GET, HEAD, and POST. For example:
REMOTE_HOST: Displays the client host name that issued the request information.
REMOTE_ADDR: Displays the IP address of the client that issued the request information.
AUTH_TYPE: Displays the user identity verification method.
REMOTE_USER: Displays the account name used by the user who accessed the protected page.
4. Fsize: Displays the size of the specified file. The output format can be customized by combining the sizefmt parameter of the config command.
5. Flastmod: Displays the last modification date of the specified file, and can be combined with the timefmt parameter of the config command to control the output format.
Here, we can use the flashmod parameter to display the update dates of all linked pages on a page. The method is as follows:
File
Another File
The displayed result is:
File April 19, 2000
Another File January 08, 2000
6. Exec
The Exec command can execute CGI scripts or shell commands. The usage method is as follows:
Cmd: Use /bin/sh to execute the specified string. If SSI uses the IncludesNOEXEC option, this command will be blocked.
Cgi: Can be used to execute CGI scripts. For example, in the following example, the counter.pl script in the cgi-bin directory of the server is used to place a counter on each
page: