SSI Instruction _php Tutorial

Source: Internet
Author: User
Tags echo command netscape web server perl script
What is SHTML
Using an SSI (server Side include) HTML file name extension, SSI (server Side include), commonly referred to as "server-side
Embedding "or" server-side inclusion "is a server-based Web authoring technology similar to ASP.
How SSI works:
Before sending content to the browser, you can use the server side include (SSI) directive to include text, graphics, or application information on the Web page
In 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. For duplicates in multiple files
The text or graphic that appears, using the include file is an easy way. Storing content in a single include file without having to enter the content
All files. The include file is called with a very simple statement that instructs the WEB server to insert the content into the appropriate Web page. and
And, when you use the Include file, all changes to the content can be done in one place only.
Because files containing SSI directives require special processing, SSI file extensions must be assigned to all SSI files. The default name extension is
. stm,. shtm, and. shtml.
The Web server processes the SSI instructions while processing the Web page. When the Web server encounters an SSI directive, the contents of the containing file are inserted directly into the
into an HTML page. If the include file contains an SSI directive, the file is inserted at the same time. In addition to the basic instructions for including the file
, you can also use SSI directives to insert information about a file, such as the size of a file, or to run an application or shell command.
Web site maintenance often encountered a problem is that the structure of the site has been fixed, but in order to update a little content and have to redo a large number of pages.
SSI provides a simple and effective way to solve this problem by placing the basic structure of a Web site in a few simple HTML files (
Template), all we have to do is pass the text to the server and let the program automatically generate the page according to the template, so that managing large sites becomes
Therefore, the use of the sHTML format page is similar to ASP, but because it is the API so faster, more efficient, faster than ASP
, which is slower than HTML, but because it can be used server side contains, so make the page update easy (especially batch update banner, copyright, etc.), want to
Like, you have a piece of HTML, to be in the middle of some special service-side script, such as inserting other HTML paragraph, you choose ASP
To complete this task, but if the task is more onerous, it will take more time, such as 5 s, this time you do not use the ASP and SHTML,
Perhaps the processing time is only 4s.
What's the use of SSI?
The reason to pull SSI is due to the acronym shtml-server-parsed HTML. Contains embedded servers that contain a life-
The HTML text of the order. The server will completely read, parse, and modify the SHTML document before it is passed to the browser. sHTML
And ASP there are some similar to shtml named files, using some of SSI's instructions, just like the instructions in ASP, you can in the sHTML file
When clients access these shtml files, the server will read and interpret these shtml files, shtml
For example, you can refer to other HTML files (#include) in the shtml file with the SSI Directive,
The files that are sent to the client by the shtml are interpreted without SSI instructions. It implements the functionality that HTML does not have, which is the ability to implement
The dynamic shtml, can be said to be a kind of evolution of HTML. Like Sina's news system is like this, the news content is fixed but it's above
Ads and menus are quoted in # include.
At present, there are several uses for the following purposes:
Display server-side environment variables < #echo >
Insert text content directly into the document < #include >
Display information about Web documents < #flastmod #fsize > (such as date/size of file creation)
Direct execution of various programs on the server < #exec > (such as CGI or other executable programs)
Set SSI Information display format < #config > (such as file date/size display mode)
Advanced SSI Variables can be set using the IF condition statement.
Using SSI
SSI is a set of commands for a Web server that is embedded directly in the comments of the HTML document. Such as:

is an SSI directive that copies the contents of the "info.htm" to the current page, and when visitors visit, they see other
The HTML document displays the contents of the info.htm. The other SSI instructions are basically used in the same form as the example given earlier, and it is visible that SSI uses only
is to insert a little bit of code, the use of the form is very simple. Of course, if the Web server does not support SSI, it will simply use it as a comment
Skip the content, and the browser will ignore the information.
How do I configure SSI features on my web server?
On some Web servers (such as IIS 4.0/sambar 4.2), files that contain #include directives must be used that have been mapped to SSI for interpretation
The extension of the program; otherwise, the WEB server will not process the SSI directive; By default, the extension. stm,. shtm, and. sHTML are
Map to the Interpreter (Ssinc.dll).
Apache is based on your settings and modifies srm.conf such as:
AddType text/x-server-parsed-html. shtml will only parse the. shtml extension files for SSI instructions
AddType text/x-server-parsed-html. HTML will parse SSI instructions for all HTML documents
The Netscape Web server uses Administration server (Management Server) directly to turn on SSI functionality.
Website using the Mapping tag in the Server Admin program, the extension adds a content type of: Wwwserver/html-ssi
The Cern server does not support SSI, and can be downloaded to using SSI scams
A Perl script that enables your CERN server to use some SSI instructions. (Exec directives are not supported.) )
SSI Instruction Basic Format
Program code:

is a comment in HTML syntax that is ignored when the Web server does not support SSI.
#include is one of the SSI directives.
File is an include parameter, info.htm is the parameter value, and the name of the document that will be included in this directive.

Name of this document
Now time
Your IP address
#include demonstration
Function: Inserts the contents of the text file directly into the document page.

The file file name is a relative path to the directory that contains the document that uses the #include directive. Included files can be in the same
The first-level directory or its subdirectories, but not in the upper-level directory. such as the nav_head.htm document that represents the current directory;
File= "Nav_head.htm".
The virtual file name is the full path to the virtualized directory on the Web site. As opposed to the server document root directory under the Hoyi directory
nav_head.htm file; file= "/hoyi/nav_head.htm"
file specifies the location that contains the files relative to this document
virtual Specifies the location relative to the root directory of the server document
The file name must have an extension.
The included files can have any file extension and I think it is most convenient to use the HTM extension directly, and Microsoft recommends using the. inc extension
Name (it depends on your hobby).
Inserts a header file into the current page
Inserts a tail file into the current page
#flastmod and #fsize Demonstrations
Date #flastmod file was last updated
Length of #fsize file

file specifies the location of the containing file relative to 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, as/hoyi/info.txt represents
Note: The file name must have an extension.
Inserts the last updated date of the news.htm file in the current directory into the current page
News.htm the file size of the current directory into the current page
#exec Demonstration
Function: Inserts the output of an external program into the page. can be inserted into a CGI program or as an input to a regular application, depending on the
Whether the parameter is cmd or CGI.

CMD general application
CGI CGI script program
The password file will be displayed
The list of files in the current directory will be displayed
The CGI program gb.cgi will be executed.
The CGI program access_log.cgi will be executed.
Note: This instruction is quite handy from the example above, but there are also security issues.
Forbidden Method:
Apache, will be access.conf in the "Options includes execcgi" This line of code deleted;
In IIS, to disable the #exec command, you can modify the SSIExecDisable metabase;
Function: Specifies the format of the error message, date, and file size returned to the client browser.

ErrMsg Custom SSI Executes the error message, which can be any way you like.
SIZEFMT file size display, default to byte mode ("bytes") can be changed to kilobytes ("abbrev")
TIMEFMT time display mode, the most flexible configuration properties.
Example: Displaying a file size that does not exist

Display file size in kilobytes

Display time in a specific time format

Show today is the day of the week, a few months, time zone

Xssi (Extended SSI) is a set of advanced SSI instructions built into the Mod-include module in Apache 1.2 or later. which can be
The directives used are:
Function: Displays all environment variables that currently exist in the Web server environment.

Function: You can assign a value to a variable for use in subsequent if statements.


Action: Create a page that can change the data, which is displayed according to the requirements that are computed when using the IF statement.

Show content

Show content

Show content


Welcome to the good easy CGI factory in Zibo Hot line of the station Http://

Welcome to the good and easy CGI factory in the Http:// of the station.

Welcome to the good and easy CGI factory!

Note: The backslash used in the preceding instruction is used to replace the inner quotation marks so that they are not interpreted as an end-expression. cannot be omitted.
1. Config command
The Config command is primarily used to modify SSI's default settings. which
ErrMsg: Sets the default error message. In order to return the user-set error message normally, the errmsg parameter must be placed in the HTML file.
is placed in front of other SSI commands, otherwise the client can only display the default error message, rather than the custom information set by the user.

TIMEFMT: Defines the use format for dates and times. The TIMEFMT parameter must be used before the echo command.

The results shown are:
Wednesday, April 12, 2000
Perhaps the user is very unfamiliar with the%a%B%d used in the above example, let's summarize in tabular form some of the more commonly used in SSI
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 can be used for kilobytes and gigabytes. Similarly, the SIZEFMT parameter must be placed before the fsize command to be used.

2. Include command
The Include command can insert text or images from other documents into the currently parsed document, which is the key to the entire SSI. Pass
The include command only needs to change a file to instantly update the entire site!
The Include command has two different parameters:
Virtual: gives the path to a document on the server side.
File: Gives the relative path to the current directory, where you cannot use the ".. /", nor can you use absolute paths.

This requires that a header.html file be included in each directory.
3. Echo command
The Echo command can display 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 development of the website, those increasingly long URLs will certainly make people headache. If you use SSI, everything will be resolved. Because I
We can combine the domain name of the website with the SSI command to display the full URL, namely:
Query_string_unescaped: Displays the non-escaped query string sent by the client, where all the special characters are preceded by a
The literal character "\". For example:

Date_local: Displays the date and time when the server sets the time zone. The user can combine the timefmt parameters of the config command to customize the output information
。 For example:

The results shown are:
Saturday, the. April, the year 2000
DATE_GMT: The function is the same as date_local, except that it returns a date that is based on Greenwich Mean time. For example:

Last_modified: Displays the last update time of the current document. Again, this is a very useful feature in SSI, as long as the HTML document
Add the following line of simple text, you can dynamically display the update time on the page.

CGI Environment variables
In addition to the 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 name of the client host that sent the request information.

REMOTE_ADDR: Displays the client IP address where the request information is made.

Auth_type: Displays the authentication method for the user's identity.

Remote_user: Displays the name of the account used by the user who accessed the protected page.

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

5, Flastmod: Display the last modified date of the specified file, you can combine the timefmt parameter of the config command to control the output format.

Here, we can use the Flastmod parameter to display the updated date of all linked pages on a page. Here's how:


Another File

The results shown are:
File April 19, 2000
Another File January 08, 2000
6. Exec
The EXEC command can execute CGI scripts or shell commands. Here's how to use it:
CMD: Executes the specified string using/bin/sh. If SSI uses the INCLUDESNOEXEC option, the command will be masked.
CGI: can be used to execute CGI scripts. For example, the following example uses the script in the server Cgi-bin directory for each
To place a counter on a page: true techarticle What is shtml using SSI (serversideinclude) HTML file extension, SSI (Serversideinclude), commonly referred to as "server-side embedding" or "server-side containment", is a ...

  • Related Article

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