2.Include command
The Include command can insert text or pictures from other documents into the currently parsed document, which is the key to the entire SSI. With the Include command, you only need to change one file to instantly update the entire site!
The Include command has two different parameters. If you use the wrong parameters to update the site, not only will you fail to achieve the original intention, but you will get a lot of error messages.
Virtual: gives the virtual path to a document on the server side. For example:
$#@60;!--#include virtual="/includes/header.html" --$#@62;
In order to organize the content of the site more rationally, users can create an includes subdirectory in the root directory to store all included files. The Virtual parameter can inform the server that what is to be included is a virtual file, that is, the file and the currently parsed document are not located in the same directory, but are stored in other directories. The server will find the includes subdirectory in the root directory based on the value of this parameter. Using this method, users can put all files contained in HTML documents in one directory, and save different pages in different directories or subdirectories according to their relationship. No matter which document the server parses, it can find the included files without generating any errors.
But there is a small problem that needs to be solved. Generally, we will add some TITLE and META tags to the page. If we stipulate that all pages call the same header file, it will be very inflexible. When users encounter such a problem, they can use two include files, one to set the content before the TITLE tag, and the other to set the part after the META tag, and any custom content can be added between the two include files. For example:
$#@60;!--#include virtual="/includes/header1.html" --$#@62;
$#@60;TITLE$#@62;Your Page Title$#@ 60;/TITLE$#@62;
$#@60;LINK rel = STYLESHEET href = "http://domain.com/styles/my.css" Type = "text/css" $#@62;
$#@60;META NAME = "Description" CONTENT = " Description of page"$#@62;
$#@60;META NAME = "Keywords" CONTENT = "keywords for page" $#@ 62;
$#@60;!--#include virtual="/includes/header2.html" --$#@62;
Place page content here
$#@60;!--#include virtual="/includes/footer.html" --$#@62;
From the above we can see that including headers and footers in the page can greatly reduce the workload of site updates. But what if we want to dynamically display some content, such as the last updated time of the page? No problem, we can save the included file with the .html suffix, so that we can call other included files in the included file.
File: Give? The relative path of the current directory, in which "../" cannot be used, and absolute paths cannot be used. For example:
$#@60;!--#include file="header.html" --$#@62;
This requires each directory to contain a header.html file. Of course, using this method is not much simpler than updating every page, but it is still very convenient if the user only updates one or two files. For example, if we don't want someone unfamiliar with HTML to directly change the news page on the website, we can just let him update a separate text file and then include the file into the HMTL document, so that it will not break The original page and updated content at the same time, the best of both worlds.
3.Echo:
The Echo command can display the following environment variables:
DOCUMENT_NAME: Displays the name of the current document.
$#@60;!--#echo var="DOCUMENT_NAME" --$#@62;
The displayed result is:
index.html
DOCUMENT_URI: Displays the virtual path of the current document. For example:
$#@60;!--#echo var="DOCUMENT_URI" --$#@62;
The displayed result is:
/YourDirectory/YourFilename.html
As the website continues to develop, those longer and longer URL addresses will definitely cause headaches. If you use SSI, everything will be solved. Because we can combine the domain name of the website and the SSI command to display the complete URL, namely:
http://YourDomain$#@60;!--#echo var="DOCUMENT_URI" --$#@62;
QUERY_STRING_UNESCAPED: Displays the query string sent by the client without escaping, in which all special characters are preceded by the escape character "". For example:
$#@60;!--#echo var="QUERY_STRING_UNESCAPED" --$#@62;
DATE_LOCAL: Displays the date and time in the time zone set by the server. Users can customize the output information by combining the timefmt parameter of the config command. For example:
$#@60;!--#config timefmt="%A, the %d of %B, in the year %Y" --$#@62;
$#@60;!-- #echo var="DATE_LOCAL" --$#@62;
The displayed result is:
Saturday, the 15 of April, in the year 2000
DATE_GMT: The function is the same as DATE_LOCAL, except that the date is returned based on Greenwich Mean Time. For example:
$#@60;!--#echo var="DATE_GMT" --$#@62;
LAST_MODIFIED: Displays the last update time of the current document. Similarly, this is very practical in SSI. Adding the following simple line of text to the TML document can dynamically display the update time on the page.
$#@60;!--#echo var="LAST_MODIFIED" --$#@62;
CGI environment variables
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:
$#@60;!--#echo var="SERVER_SOFTWARE" --$#@62;
SERVER_NAME: Displays the server’s host name, DNS alias or IP address. For example:
$#@60;!--#echo var="SERVER_NAME" --$#@62;
SERVER_PROTOCOL: Displays the protocol name and version used by the client request, such as HTTP/1.0. For example:
$#@60;!--#echo var="SERVER_PROTOCOL" --$#@62;
SERVER_PORT : Displays the server’s response port. For example:
$#@60;!--#echo var="SERVER_PORT" --$#@62;
REQUEST_METHOD: Displays the client’s document request method, including GET, HEAD, and POST. For example:
$#@60;!--#echo var="REQUEST_METHOD" --$#@62;
REMOTE_HOST: Displays the name of the client host that issued the request information.
$#@60;!--#echo var="REMOTE_HOST" --$#@62;
REMOTE_ADDR: Displays the IP address of the client that issued the request information.
$#@60;!--#echo var="REMOTE_ADDR" --$#@62;
AUTH_TYPE: Displays the user identity verification method.
$#@60;!--#echo var="AUTH_TYPE" --$#@62;
REMOTE_USER: Displays the account name used by the user who accessed the protected page.
$#@60;!--#echo var="REMOTE_USER" --$#@62;
4.Fsize: Displays the size of the specified file. The output format can be customized by combining the sizefmt parameter of the config command.
$#@60;!--#fsize file="index_working.html" --$#@62;
5.Flastmod: Displays the last modification date of the specified file, and can be combined with the timefmt parameter of the config command to control the output format.
$#@60;!--#config timefmt="%A, the %d of %B, in the year %Y" --$#@62;
$#@60;!-- #flastmod file="file.html" --$#@62;
Here, we can use the flashmod parameter to display the update date of all linked pages on a page. Here’s how:
$#@60;!--#config timefmt=" %B %d, %Y" --$#@62;
$#@60;A HREF="/directory/file.html" $#@62;File$#@60;/A$#@62;
$#@60;!--#flastmod virtual="/directory/file.html" --$#@62;
$#@60;A HREF="/another_directory/another_file.html"$#@62;Another File$#@60;/A$#@62;
$#@60;!--#flastmod virtual ="/another_directory/another_file.html" --$#@62;
The displayed result is:
File April 19, 2000
Another File January 08, 2000
Some readers may think that two links are so complicated and 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 use of blastmod to display the modification date.
6.Exec
The Exec command can execute CGI scripts or shell commands. How to use:
Cmd: Use /bin/sh to execute the specified string. If SSI uses the IncludesNOEXEC option, this command will be blocked.
Cgi: Can be used to execute CGI scripts. For example, in the following example, the counter.pl script in the cgi-bin directory of the server is used to place a counter on each page:
$#@60;!--#exec cgi="/cgi-bin/counter.pl" --$#@62;