I used it when I was working, and I never used it again. Let's review this inclusion method.
Shtml tutorial
What is SSI used?
SSI is the first acronyms of server side include. Contains HTML text containing commands on the embedded server. Before being sent to a browser, the server will completely read, analyze, and modify the shtml document.
Shtml is similar to ASP. Some SSI commands are used in files named after shtml, just like ASP commands. You can write ssi commands in the shtml file, when the client accesses these SHTML files, the server reads and interprets these SHTML files and explains the SSI commands contained in The shtml files.
For example, you can use the SSI command in the shtml file to reference other HTML files (# include). The files that the server sends to the client do not have SSI commands. It implements a function not available in HTML, that is, it can implement a dynamic shtml. It can be said that it is an evolution of HTML. Like Sina's news system, the news content is fixed, but the advertisements and menus on it are referenced by # include.
At present, it mainly has the following usage:
1. Display Server Environment Variables <# echo>
2. Insert text content directly into the document <# include>
3. Display Web Document Information <# flastmod # fsize> (for example, file creation date/size)
4. directly execute variousProgram<# Exec> (for example, CGI or other executable programs)
5. Set the SSI information display format <# config> (such as the file creation date/Size Display Mode). Advanced SSI <xssi> allows you to set variables to use the if Condition Statement.
Use SSI
SSI is a set of commands provided for Web servers. These commands can be directly embedded in the comments of HTML documents. For example:
<! -- # Include file = "info.htm" -->
It is an SSI command, which serves to bring the content of "info.htm" to the front page. When a visitor visits the page, his htmldocument displays the content of info.htm.
The usage of other SSI commands is similar to the previous example. It can be seen that SSI only inserts a littleCodeIt is easy to use.
Of course, if the web server does not support SSI, it simply uses it as a comment and directly skips the content. The browser also ignores this information.
How can I configure the SSI function on my web server?
On some Web servers (such as IIS 4.0/Sambar 4.2), files containing the # include command must use extensions that have been mapped to the SSI interpreter; otherwise, the web server will not process the SSI command; by default, the extension. STM ,. SHTM and. shtml is mapped to the interpreter (ssinc. DLL ).
Apache depends on your settings. Modify SRM. conf as follows:
Addtype text/X-server-parsed-html. shtml parses only the file with the .shtml extension SSI command
Addtype text/X-server-parsed-html. html parses SSI commands for all HTML documents
The Netscape Web server directly uses the Administration Server to enable the SSI function.
Website uses the mapping label in the server admin program. The content type added with the extension is wwwserver/html-ssi.
The CERN server does not support ssi. You can use the SSI fraud method to download a Perl script on the http://sw.cse.bris.ac.uk/WebTools/fakessi.html to make your CERN server use some SSI commands. (Exec commands are not supported .)
SSI command basic format
SSI command basic format:
Program code:
<! -- Command name = "Command Parameters">
<! -- Command name = "Command Parameters">
Such as program code:
<! -- # Include file = "info.htm" -->
<! -- # Include file = "info.htm" -->
Note:
1. <! --> Indicates the annotation in HTML syntax. This information is ignored when the web server does not support ssi.
2. # include is one of the SSI commands.
3. file is the include parameter and info.htm is the parameter value. In this instruction, specify the document name to be included.
Note:
1. <! -- There is no space between the and #, and only a space exists between the SSI command and the parameter.
2. The above punctuation = "" cannot be less than one.
3. the SSI command is case-sensitive, so the parameter must be in lower case.
SSI instructions
# Echo demonstration
Purpose:
Insert environment variables into the page.
Syntax:
Program code:
<! -- # Echo Var = "variable name" -->
This document name: program code:
<! -- # Echo Var = "document_name" -->
Current Time: program code:
<! -- # Echo Var = "date_local" -->
<! -- # Echo Var = "date_local" -->
Your IP address is the program code:
<! -- # Echo Var = "remote_addr" -->
# Include example
Purpose:
Insert the content of a text file to the document page.
Syntax:
Program code:
<! -- # Include file = "file name" -->
<! -- # Include virtual = "file name" -->
The file name is a relative path, which is relative to the directory of the document using the # include command. The contained file can be in the same level directory or its sub-directory, but not in the upper level directory. For example, the nav_head.htm document under the current directory is file = "nav_head.htm ".
The Virtual File name is the complete path of the virtual directory on the web site. For example, if the parameter is relative to the nav_head.htm file in the hoyidirectory under the Server File root directory, it is virtual = "/hoyi/nav_head.htm"
Parameters:
File specifies the location of the contained file relative to this document
Virtual specifies the location relative to the root directory of the server document
Note:
1. The file name must have an extension.
2. The contained file can have any file extension. I think it is most convenient to directly use the HTM extension. Microsoft recommends using the. inc extension (this depends on your hobby ).
Example:
Program code:
<! -- # Include file = "nav_head.htm" --> Insert the header file to the current page.
<! -- # Include file = "nav_foot.htm" --> Insert the last file to the current page.
# Flastmod and # fsize demonstration
Purpose: # The Last Update date of the flastmod File
# Fsize file length
Syntax:
Program code:
<! -- # Flastmod file = "file name" -->
<! -- # Fsize file = "file name" -->
Parameters:
File specifies the position of the file to be included in this document, such as info.txt under the current directory.
Virtual specifies the location relative to the root directory of the server document, as shown in/hoyi/info.txt
Note:
The file name must have an extension.
Example:
Program code:
<! -- # Flastmod file = "news.htm" -->
Insert the latest update date of the news.htm file in the current directory to the current page.
Program code:
<! -- # Fsize file = "news.htm" -->
Add the news.htm file in the current directory to the current page.
# Exec demonstration
Purpose:
Insert the output of an external program to the page. The input of a CGI program or a general application can be inserted, depending on whether the parameter is cmd or CGI.
Syntax:
Program code:
<! -- # Exec cmd = "file name" -->
<! -- # Exec CGI = "file name" -->
Parameters:
CMD common application
CGI script program
Example:
Program code:
<! -- # Exec cmd = "cat/etc/passwd" --> the password file is displayed.
<! -- # Exec cmd = "DIR/B" --> the file list in the current directory is displayed.
<! -- # Exec CGI = "/cgi-bin/GB. cgi" --> the CGI program GB. cgi is executed.
<! -- # Exec CGI = "/cgi-bin/access_log.cgi" --> the CGI program access_log.cgi is executed.
Note:
As shown in the preceding example, this command is quite convenient, but there are also security problems.
Method prohibited:
. Apache: Delete the "options exist des execcgi" line of code in access. conf;
To disable the # EXEC command in IIS, you can modify the ssiexecdisable metadatabase;
# Config
Purpose: Specify the error message, date, and file size returned to the client browser.
Syntax:
Program code:
<! -- # Config errmsg = "custom error message" -->
<! -- # Config sizefmt = "display unit" -->
<! -- # Config timefmt = "display format" -->
Parameters:
Errmsg custom SSI execution error message, which can be any method you like.
Display Mode of sizefmt file size. The default mode is byte mode ("bytes"), which can be changed to kilobytes ("abbrev ")
Timefmt time display mode, the most flexible configuration attributes.
Example: display the size of a non-existing file
Program code:
<! -- # Config errmsg = "server execution error, please contact the Administrator yiho@126.com, thank you! "-->
<! -- # Fsize file = "nonexistent file .htm" -->
Display file size in kilobytes
Program code:
<! -- # Config sizefmt = "abbrev" -->
<! -- # Fsizefile = "news.htm" -->
Display time in a specific time format
Program code:
<! -- # Config timefmt = "% Y year/% m month % d day week % W Beijing time % H: % m: % s, % Y years passed % J days today is % u week of % Y years "-->
<! -- # Echo Var = "date_local" --> display the day of the week, month, and Time Zone
<! -- # Config timefmt = "today % A, % B, server time zone is % Z, yes" -->
<! -- # Echo Var = "date_local" -->
Xssi
Xssi (Extended SSI) is a set of advanced SSI commands built into the mod-include module of Apache 1.2 or later.
The available Commands include:
# Printenv
# Set
# If
# Printenv
Purpose: Display All environment variables currently in the web server environment.
Syntax: program code:
<! -- # Printenv -->
# Set
Function: assign a value to the variable to be used in the later if statement.
Syntax: program code:
<! -- # Set Var = "variable name" value = "variable value" -->
Parameter: None
Example: program code:
<! -- # Set Var = "color" value = "red" -->
# If
Purpose: Create a page that can change the data. The data is displayed according to the requirements calculated when the if statement is used.
Syntax: program code:
<! -- # If expr = "$ variable name = \" variable value A \ "" -->
Display content
<! -- # Elif expr = "$ variable name = \" variable value B \ "" -->
Display content
<! -- # Else -->
Display content
<! -- # Endif "-->
Example:
Program code:
<! -- # If expr = "$ SERVER_NAME = \" hoyi.zb169.net \ "-->
Welcome to the substation http://hoyi.zb169.net of easy CGI factory at Yunbo hotline.
<! -- # Elif expr = "$ SERVER_NAME = \" linux.cqi.com.cn \ "" -->
Welcome to easy CGI factory substation http://linux.cqi.com.cn in Sun City /~ Hoyi.
<! -- # Else -->
Welcome to the easy CGI factory!
<! -- # Endif "-->
Note: It is used for the backslash in the preceding command to replace internal quotation marks so that they are not interpreted as an end expression. It cannot be omitted.
1. config command
The Config command is mainly used to modify the default settings of SSI. Where:
Errmsg: sets the default error message. To return user-defined error messages normally, the errmsg parameter in the HTML file must be placed before other SSI commands; otherwise, the client can only display default error messages, instead of user-defined information.
<! -- # Config errmsg = "error! Please email webmaster@mydomain.com -->
Timefmt: defines the format of the date and time. The timefmt parameter must be used before the echo command.
<! -- # Config timefmt = "% A, % B % d, % Y" -->
<! -- # Echo Var = "last_modified" -->
The result is as follows:
Wednesday, 10000l 12,200 0
Maybe the user is unfamiliar with % A % B % d in the previous example. Below we will summarize some of the commonly used Date and Time formats in SSI in the form of a table.
Sizefmt: determines whether the file size is expressed in bytes, kilobytes, or megabytes. In bytes, the parameter value is "bytes". You can use the abbreviations for kilobytes and megabytes. Similarly, the sizefmt parameter must be placed before the fsize command.
<! -- # Config sizefmt = "bytes" -->
<! -- # Fsize file = "index.html" -->
2. include command
The include command can insert text or images from other documents into the currently parsed documents, which is the key to the entire ssi. By using the include command, you only need to change one file to instantly update the entire site!
The include command has two different parameters:
Virtual: the virtual path to a document on the server. For example:
<! -- # Include virtual = "/Includes/header.html" -->
File: Specifies the relative path to the current directory. "../" cannot be used or an absolute path. For example:
<! -- # Include file = "header.html" -->
In this case, each directory contains a header.html file.
3. Echo command
The echo command displays the following environment variables:
Document_name: displays the name of the current document.
<! -- # Echo Var = "document_name" -->
The result is as follows:
Index.html
Document_uri: displays the virtual path of the current document. For example:
<! -- # Echo Var = "document_uri" -->
The result is as follows:
/Yourdirectory/yourfilename.html
With the continuous development of websites, those longer and longer URLs will be a headache. If SSI is used, everything will be solved. Because we can combine the website domain name with the SSI command to display the complete URL, that is:
Http: // yourdomain <;! -- # Echo Var = "document_uri" -->
Query_string_unescaped: displays unescaped query strings sent by the client. All special characters are preceded by the Escape Character "\". For example:
<! -- # Echo Var = "query_string_unescaped" -->
Date_local: displays the date and time when the server sets the time zone. You can combine the timefmt parameter of the config command to customize the output information. For example:
<! -- # Config timefmt = "% A, the % d of % B, in the year % Y" -->
<! -- # Echo Var = "date_local" -->
The result is as follows:
Saturday, the 15 of each l, in the year 2000
Date_gmt: similar to date_local, but returns a date based on Greenwich Mean Time. For example:
<! -- # Echo Var = "date_gmt" -->
Last_modified: displays the Last Update Time of the current document. Similarly, this is a very practical feature of SSI. You only need to add the following simple lines of text to the HTML document to dynamically display the Update Time on the page.
<! -- # Echo Var = "last_modified" -->
CGI Environment Variable
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:
<! -- # Echo Var = "server_software" -->
SERVER_NAME: displays the host name, DNS alias, or IP address of the server. For example:
<! -- # Echo Var = "SERVER_NAME" -->
Server_protocol: displays the protocol name and version used by the client request, such as HTTP/1.0. For example:
<! -- # Echo Var = "server_protocol" -->
Server_port: display the server's response port. For example:
<! -- # Echo Var = "server_port" -->
Request_method: display the client's document request methods, including get, Head, and post. For example:
<! -- # Echo Var = "request_method" -->
Remote_host: the name of the client host that sends the request information.
<! -- # Echo Var = "remote_host" -->
Remote_addr: displays the IP address of the client sending the request.
<! -- # Echo Var = "remote_addr" -->
Auth_type: shows the authentication method for user identity.
<! -- # Echo Var = "auth_type" -->
Remote_user: displays the account name used by the user accessing the protected page.
<! -- # Echo Var = "remote_user" -->
4. fsize:Display the size of the specified file. You can use the sizefmt parameter of the config command to customize the output format.
<! -- # Fsize file = "index_working.html" -->
5. flastmod:Display the last modification date of the specified file. You can control the output format with the timefmt parameter of the config command.
<! -- # Config timefmt = "% A, the % d of % B, in the year % Y" -->
<! -- # Flastmod file = "file.html" -->
Here, we can use the flastmod parameter to display the update dates of all links on a page. The method is as follows:
<! -- # Config timefmt = "% B % d, % Y" -->
File
<! -- # Flastmod virtual = "/directory/file.html" -->
Another File
<! -- # Flastmod virtual = "/another_directory/another_file.html" -->
The result is as follows:
File Transfer l 19,200 0
Another file January 08,200 0
6. Exec
The exec command can execute CGI scripts or shell commands. The usage is as follows:
CMD: run the specified string using/bin/sh. If SSI uses the IncludesNOEXEC option, the command will be blocked.
CGI: it can be used to execute CGI scripts. For example, in the following example, the counter. pl script under the cgi-bin directory on the server is used to place a counter on each page?
<! -- # Exec CGI = "/cgi-bin/counter. pl" -->