Summary SSI is the abbreviation of English Server Side Includes, translated into Chinese is the meaning of the server side. From a technical point of view, SSI is in an HTML file, which can call or pointers that are called by comment. SSI has a powerful feature, as long as a simple SSI command can realize the content update, time and date of the entire website, and complex features such as SHELL and CGI scripts. SSI can be said to be the best helper for website developers who have a shortage of funds, time, and workload. This article will mainly bind to the APACHE server to introduce the use of SSI.
How to start SSI?
Under the Apache server, you can start SSI by direct editing the server profile or create a .htaccess file in a directory you need to use the SSI. The specific process is as follows:
1. Server profile
If the user has access to the server profile, you can start SSI by editing file access.conf and srm.conf.
First log in to the server, find the deposit directory of the configuration file, open the file SRM.CONF using any text editor, find the following lines:
# If you want to use server side includes, or CGI outside # ScriptAliased directories, uncomment the following lines. #AddType text / x-server-parsed-html .shtml #AddType application / x-httpd-CGI .CGI note that high version Apache may be these lines: # # to use server-pased HTML Files # #addtype text / html .shtml #addhandler server-pased .shtml
There may be no such annotation instruction lines in the user's configuration file, but as long as you find two rows starting with ADDTYPE and remove the "#" symbol of each row.
Save the modifications made, then open the file access.conf. Users need to find some of the part of setting the DocumentRoot (root file) in the file. Generally, the text is as follows:
# This kind be changing to wherever you set documentroot to.
If the user does not want the script or shell command, you can add keyword INCLUDESNOEXEC in the Options option row, which allows SSI, but cannot perform CGI or script commands (Note: High versions of the Apache server, the above mentioned content Already included in the configuration file httpd.conf).
2. Create a file .htaccess If the user cannot access the server profile directly, you can use the file editor to create a file named .htaccess. Note that the file name must have a symbol "." So the server can know that the file is hidden file, thereby increasing the security of the file to avoid error operations. In the .htaccess file, you need to add the following three lines of text: Options Indexes Followsymlinks include addtype application / x-httpd-cgi .cgi addtype text / x-server-pased-html .shtml
After completion, you can upload the .htaccess file to the corresponding directory of the server, which is valid for all subdirectories. If the user wants to disable the CGI or shell command on the directory level, you can add keyword incrudesnoexec on the .htaccess file.
3. Use .shtml or .html?
Any file containing SSI must pass the server's parsing process before it is submitted to the client. This will increase the server's load. If the user only wants to use SSI to use SSI in several special pages, you can change the file's suffix name to .shtml, so that the server can only parse the .shtml file containing the SSI. On the other hand, if there is a multiple page using SSI, but the user does not want to use .SHTML's suffix name, you can use the following command line in the .htaccess file:
AddType text / x-server-pased-html .html
How to use SSI?
SSI follows the following format when using:
Among them, Directive is the command name sent to the server. Parameter is the operation object of the instruction, and the value is the command processing result of the user desired.
All SSI commands start with "".
The SSI command contains six major classes and their respective parameters, as follows:
Command name
parameter list
We will introduce one by one.
1, config command
The config command is primarily used to modify the default settings of the SSI. among them:
Errmsg: Set the default error message. In order to be able to return the user setting error information, the errmsg parameter must be placed in front of the other SSI command in the HTML file, otherwise the client can only display the default error message instead of the custom information set by the user.
Timefmt: Defines the use format of the date and time. The TimeFmt parameter must be used before the echo command.
The result is:
Wednesday, April 12, 2000
Perhaps the user is very unfamiliar with the% a% B% D used in the previous example. Here we summarize some of the more common date and time formats in the SSI in the form of a table.
SIZEFMT: Deciding that the file size is indicated by bytes, kilobytes or megabytes. If in bytes, the parameter value is "BYTES"; the abbreviated form can be used for kilobytes and megabytes. Similarly, the SIZEFMT parameter must be placed in front of the fsize command.
2, incrude command
The include command can insert text or images in other documents into the currently parsed document, which is the key to the entire SSI. You can instantly update the entire site instantly through the incrude command.
The incrude command has two different parameters:
Virtual: Gives the virtual path to a document to the server. E.g:
File: Give the relative path to the current directory, where "../" cannot be used, and the absolute path cannot be used. E.g:
This requires all of each directory that contains a header.html file.
3, echo command
The echo command can display the following environment variables:
Document_name: Displays the name of the current document.
The display result is:
INDEX.HTML
Document_uri: Displays the virtual path of the current document. E.g:
The display result is:
WeighDirectory /YourFileName.html
As the website is constantly evolving, those increasingly long URL addresses will definitely make people a distress. 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 full URL, ie:
http:// YourDomain
Query_string_unescaped: Displays the query string sent by the client unsubmitted by the unflied process, where all of the special characters have escape characters "/". E.g:
Date_local: Displays the date and time of the server setting time zone. The user can customize the output information in conjunction with the TIMEFMT parameters of the config command. E.g:
The result is:
Saturday, The 15 of April, in The Year 2000
Date_gmt: The function is the same as Date_Local, but returns to the date based on the Greenwich time. E.g:
Last_Modified: Displays the last update time of the current document. Similarly, this is a very practical feature in SSI, as long as the following simple text is added to the HTML document, you can update the update time on the page.
CGI environment variable
In addition to the SSI environment variable, 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 client host name that issues request information. remote_addr: Displays the client IP address that issues request information. auth_type: Displays the authentication method of the user identity. remote_user: Displays the account name used by the user who is accessing the protected page.
, Fsize: Displays the size of the specified file, which can be customized in combined with the SIZEFMT parameter of the config command.
5, FLASTMOD: Displays the final modification date of the specified file, which can combine the TIMEFMT parameter control output format of the config command.
Here, we can use the FLASTMOD parameter to display the update date of all links on a page. Methods as below:
file Another file The result is: File April 19, 2000 Another File January 08, 2000
6, EXEC
The exec command can execute the CGI script or shell command. The method is as follows:
CMD: Use / bin / SH to perform the specified string. If the SSI uses the IncludeSnoExec option, the command will be blocked.
CGI: Can be used to perform the CGI script. For example, the following example uses the counter.pl scripker under the Directory of the Directory in each page to place a counter at each page: