SSI Usage details (turn two)

Source: Internet
Author: User
Tags date config header include variables version domain name root directory
Detailed 2.Include command

The Include command inserts text or pictures from other documents into the currently parsed document, which is the key to the entire SSI. You can update the entire site in an instant by simply changing one file with the Include command!

The include command has two different parameters, if you use the wrong parameters to update the site, not only to achieve the original intention, but will get a lot of error messages.

Virtual: gives a dummy path to a document on the server side. For example:

<!--#include virtual= "/includes/header.html"-->

For a more reasonable organization of the content of the site, users can create includes subdirectories under the root directory to hold all the included files. The virtual parameter notifies the server that it is going to contain a dummy file, that is, that the file is not in the same directory as the document currently being parsed, but is stored in a different directory. Depending on the value of the parameter, the server finds the includes subdirectory under the root directory. With this method, the user can put all the files contained in the HTML document in a directory, and according to the relationship between the different pages stored in different directories or subdirectories. No matter what document the server resolves to find the included file, no error occurs.

But here's a little problem to solve. In general we will add some title and meta tags to the page, if we require all the pages to call the same header file, it will appear very inflexible. When a user encounters a problem like this, you can use two include files, one before the title tag, the other after the meta tag, and you can add any custom content between the two included files. For example:

<!--#include virtual= "/includes/header1.html"-->
<title>your Page title</title>
<link rel = STYLESHEET href = "Http://domain.com/styles/my.css" Type = "Text/css" >
<meta NAME = "Description" CONTENT = "Description of page" >
<meta NAME = "Keywords" CONTENT = "Keywords for page" >
<!--#include virtual= "/includes/header2.html"-->

Place page Content here

<!--#include virtual= "/includes/footer.html"-->

From the above we can see that by including headers and footers in the page, you can significantly reduce the amount of site updates. But what if we want to dynamically display something, such as the last time the page was updated? No problem, we can save the containing file using the. html suffix so that other include files can be invoked in the include file.

File: Gives the relative path to the current directory, where you cannot use the. /"And you cannot use absolute paths. For example:

<!--#include file= "header.html"-->

This requires a header.html file to be included in each directory. Of course, using this method is not much simpler than updating each page, but it is convenient if the user updates only one or two files. For example, if we do not want a person unfamiliar with HTML to directly change the news page in the site, you can just let him update a separate text file, and then include the file in the HMTL document, so that it will not break the original page, but also updated the contents of the two worlds.


3.Echo:

The echo command can display the following environment variables:

Document_name: Displays the name of the current document.

<!--#echo var= "Document_name"-->

Display results as:

Index.html

Document_uri: Displays the virtual path of the current document. For example:

<!--#echo var= "Document_uri"-->

Display results as:

/yourdirectory/yourfilename.html

With the development of the Web site, the increasingly long URL address will certainly make people headache. If you use SSI, everything will be solved. Because we can combine the domain name of the website with the SSI command to display the complete URL, namely:

http://yourdomain<!--#echo var= "Document_uri"-->

Query_string_unescaped: Displays the query string sent by the client without escaping processing, where all the special characters are preceded by an escape character "\". For example:

<!--#echo var= "query_string_unescaped"-->

Date_local: Displays the date and time the server set the time zone. The user can combine the timefmt parameters 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"-->

Display results as:

Saturday, the April, in the year 2000

DATE_GMT: The function is the same as date_local, except that it returns a date based on Greenwich Mean time. For example:

<!--#echo var= "Date_gmt"-->

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

<!--#echo var= "last_modified"-->


CGI Environment variables

In addition to the SSI environment variables, the echo command can 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 server's host name, DNS alias, or IP address. 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: Displays the server's response port. For example:

<!--#echo var= "Server_port"-->

Request_method: Displays the client's document request methods, including get, head, and post. For example:

<!--#echo var= "Request_method"-->

Remote_host: Displays the name of the client host that sent the request information.

<!--#echo var= "Remote_host"-->

REMOTE_ADDR: Displays the client IP address that sent the request information.

<!--#echo var= "REMOTE_ADDR"-->

Auth_type: The authentication method that displays the user's 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: Displays the size of the specified file and can be customized with the sizefmt parameter of the config command.

<!--#fsize file= "index_working.html"-->

5.Flastmod: Displays the last modification date of the specified file, which can be combined with the timefmt parameter of the config command to control the output format.

<!--#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 updated date of all the linked pages on a page. The method is as follows:

<!--#config timefmt= "%B%d,%Y"-->
<a href= "/directory/file.html" >File</A>
<!--#flastmod virtual= "/directory/file.html"-->
<a href= "/another_directory/another_file.html" >another file</a>
<!--#flastmod virtual= "/another_directory/another_file.html"-->

Display results as:

File April 19, 2000
Another File January 08, 2000

Perhaps some readers will think that two links are so complicated that it is not convenient at all. In fact, if there are 20 or more links on the page, and each link is updated regularly, you can see the effect of using Flastmod to display the modified date.


6.Exec

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

CMD: Executes the specified string using/bin/sh. If SSI uses the INCLUDESNOEXEC option, the command is masked.

CGI: can be used to execute CGI scripts. For example, the following example uses the counter.pl script program in the server-side Cgi-bin directory to place a counter on each page:

<!--#exec cgi= "/cgi-bin/counter.pl"-->


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.