Server-side inclusion, Embedding technology SSI (Server Sideinc lude) detailed _linux

Source: Internet
Author: User
Tags echo command

SSI profile

SSI is useful in static files, separating some variable modules, such as the daily charts. Its main functions are:

1. Display server-side environment variables < #echo >
2. Insert text content directly into the document < #include >
3. Display information related to Web documents < #flastmod #fsize > (such as file date/size, etc.)
4. Direct execution of various programs on the server < #exec > (such as CGI or other executable programs)
5. Set SSI Information display format < #config > (such as file production date/size display)
6. Advanced ssi<xssi> can set variables to use if conditional statements. Apache, Nginx, and so on support SSI commands, configuration can be, Nginx configuration can refer to:

Http://wiki.nginx.org/HttpSsiModuleChs

The default extension for SSI is. stm,. shtm and. shtml

SSI syntax

Example:

<!--#command param= "value"-->

The syntax for SSI is very simple, but the following points need to be noted in use:

No spaces between 1.<!– and #
2.SSI Case Sensitive
3. All value must be written in quotation marks

SSI command

Config command

The config command is primarily used to modify the default settings for SSI, such as time format, default error message, File size unit.

Set default error message: ErrMsg

Copy Code code as follows:
<!--#config errmsg= "error,please contact webmaster@mail.com"-->

Define date and time formats: TIMEFMT
Copy Code code as follows:
<!--#config timefmt= "%A,%B%d,%Y"-->

Define File size units
Copy Code code as follows:
<!--#config sizefmt= "bytes"-->

The config command only takes effect for commands that are subsequently used. At the same time, the later defined settings have a higher priority, overwriting the previous settings.

Include command

Include naming may be the most used command in SSI and is the most important embodiment of SSI;
Include commands can insert text or pictures from other documents into the currently parsed document, and you can update the entire site in an instant by simply changing one file with the Include command!

Copy Code code as follows:
<!--#include virtual= "/inc/header.inc"-->
<!--#include file= "Inc/desc.inc"-->

The include command supports the introduction of a file via a virtual path, as well as the introduction of a relative path to a file, which is not limited to the type of file referenced.

Set command

You can use set to define variables:

Copy Code code as follows:
<!--#set var= "blog" value= "Http://www.jb51.net"-->

You can use the variable after the definition:
Copy Code code as follows:
<!--#echo var= "blog"-->

Use environment variables when defining variables:
Copy Code code as follows:
<!--#set var= "fname" value= "${document_name}${document_uri}"-->

If a single environment variable can be split without {}:
Copy Code code as follows:
<!--#set var= "fname" value= "$DOCUMENT _name"-->

References to environment variables need to use the $ prefix, which can be escaped by \$ if $ is used only as a character.

echo command

ECHO displays variable values, including custom variables, environment variables

Copy Code code as follows:
<!– #echo var= "Document_name" –>

Note: The environment variable used in the Echo command does not need to use the $ prefix. The main environment variables for SSI are as follows:

Name Description Type
Document_name Current document name Ssi
Document_uri Current document virtual path Ssi
query_string_unescaped A query string sent by a client that is not escaped, with the escape character "\" in front of all special characters. Ssi
Date_local Date and time the time zone was set by the server Ssi
Date_gmt function is the same as date_local, but returns a date based on Greenwich Mean Time Ssi
Last_modified Last update time for the current document Ssi
Server_software Name and version of the Server software Cgi
server_name Host name, DNS alias, or IP address of the server Cgi
Server_protocol The protocol name and version used by the client request Cgi
Server_port Response port for the server Cgi
Remote_host Name of the client host that made the request information Cgi
Remote_addr The client IP address that issued the request information Cgi
Auth_type authentication method of user identity Cgi
Remote_user Account name used by the user accessing the protected page Cgi

More environment variables can use the PRINTENV command to view the PRINTENV command to display all environment variables

Fsize command

Displays the size of the specified file, which can be combined with config sizefmt to specify the output format.

Copy Code code as follows:

<!--output the current document size-->
<!--#fsize file= "$DOCUMENT _name"-->
<!--#fsize virtual= "$DOCUMENT _uri"-->

Flastmod command

Displays the date of the last update of the specified file, which can be combined with config sizefmt to specify the output format.

Copy Code code as follows:

<!--output the current document size-->
<!--#flastmod file= "$DOCUMENT _name"-->
<!--#flastmod virtual= "$DOCUMENT _uri"-->

EXEC command

The Exec command can execute CGI scripts or shell commands. Use the following methods:

1.CMD: Executes the specified string using/bin/sh. If SSI uses the INCLUDESNOEXEC option, the command will be blocked

2.CGI: Can be used to execute CGI scripts

If ... Statement

SSI can also be conditional judgment statement if, syntax is as follows:

Copy Code code as follows:
<!--#if expr= "Test_condition"-->
<!--#elif expr= "Test_condition"-->
<!--#else-->
<!--#endif-->

Example:
Copy Code code as follows:

<!--#if expr= "$DOCUMENT _name=index.shtml"-->
<p> this is through if to determine the current document named "Index.shtml" after the display </p>
<!--#elif expr= "$DOCUMENT _name=index.html"-->
<p> this is through if to determine the current document named "Index.html" after the display </p>
<!--#else-->
<p> is neither "index.shtml" nor "index.html" </p>
<!--#endif-->
Demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.