Shtml tutorial (2)

Source: Internet
Author: User
Tags echo command
# Flastmod and # fsize demonstrate functions: # The Last Update date of the flastmod file # The length syntax of the fsize file :! -- # Flastmodfile name --! -- # Fsizefile file name -- parameter: The filepath includes the info.txt file virt that is relative to the current file, such as info.txt.

# Flastmod and # fsize demonstrate functions: # The Last Update date of the flastmod file # The length syntax of the fsize file :! -- # Flastmod file = "file name "--! -- # Fsize file = "file name" -- parameter: file specifies the position of the file to be included in this document. For example, info.txt indicates the info.txt file virt in the current directory.

# FlastmodAnd# FsizeDemonstration

Purpose:

# FlastmodLast file update date
# FsizeFile Length

Syntax:


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:

Insert the latest update date of the news.htm file in the current directory to the current page.
Add the news.htm file in the current directory to the current page.

# ExecDemonstration

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:


Parameters:

CmdRegular applications
CgiCGI script program

Example:

The password file is displayed.
The file list in the current directory is displayed.
The CGI program gb. cgi will be executed.
The CGI program access_log.cgi will be executed.

Note: As shown in the preceding example, this command is quite convenient, but there are also security problems.

Method prohibited:

1. Apache: Delete the "Options exist des ExecCGI" line of code in access. conf;

2. to disable the # exec command in IIS, modify the SSIExecDisable metadatabase;

# Config

Purpose: Specify the error message, date, and file size returned to the client browser.

Syntax:



Parameters:

ErrmsgCustom SSI execution error message, which can be any method you like.
SizefmtFile size display mode. The default format is byte ("bytes"). You can change the format to kilobytes ("abbrev ")
TimefmtTime Display Mode, the most flexible configuration of attributes.

Example: display the size of a non-existing file


Display file size in kilobytes

Syntax:


Display time in a specific time format


Displays the day of the week, month, and time zone.

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:

# Set

Function: assign a value to the variable to be used in the later if statement.

Syntax:

Example:

# 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:


Display content

Display content

Display content

Example:


Http://www.baidu.com

Http://www.google.com

Welcome to Afly's Blog!

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,ConfigCommand

The Config command is mainly used to modify the default settings of SSI. Where:

Errmsg: Set 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.

Timefmt: Defines the format of date and time. The Timefmt parameter must be used before the echo command.


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.


2,IncludeCommand

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: Provides a virtual path to a document on the server.
File: Indicates the relative path to the current directory. "../" cannot be used or an absolute path.


In this case, each directory contains a header.html file.

3,EchoCommand

The Echo command displays the following environment variables:

DOCUMENT_NAME: Displays the name of the current document.
DOCUMENT_URI: Displays the virtual path of the current document. For example:


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

QUERY_STRING_UNESCAPED: Displays unescaped query strings sent by the client. All special characters are preceded by the Escape Character "/". For example:

DATE_LOCAL: Display 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:


The result is as follows:

Saturday, the 15 of each l, in the year 2000

DATE_GMT: The function is the same as that of DATE_LOCAL, except that the returned date is based on the Greenwich Mean Time. For example:

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.

CGIEnvironment 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:

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: display the server's response port. For example:

REQUEST_METHOD: display the client's document request methods, including GET, HEAD, and POST. For example:

REMOTE_HOST: the name of the client host that sends the request information.

REMOTE_ADDR: displays the IP address of the client sending the request.

AUTH_TYPE: shows the authentication method for user identity.

REMOTE_USER: displays the account name used by the user accessing the protected page.

4,Fsize: Displays the size of the specified file. You can use the sizefmt parameter of the config command to customize the output format.

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.


Here, we can use the flastmod parameter to display the update dates of all links on a page. The method is as follows:


File

Another File

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: Use/bin/sh to execute the specified string. 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:

AboutSHTMLAndHTMLDifference

Let's take a look at the differences between SHTML and HTML. If we use one sentence to explain that SHTML is not HTML but a Server API, shtml is the server's dynamic html.

Both are in hypertext format, but shtml is a file used for SSI technology. That is, the Server Side Include -- SSI Server contains commands. If the Web Server has the SSI function, most (especially Unix-based) WEB servers, such as Netscape Enterprise Server, support SSI commands.

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.