SSI use Details (a) _php tutorial

Source: Internet
Author: User
Tags echo command time and date
Have you ever been or are you worried about how you can make changes to a site with thousands of pages in the shortest possible time? Then you can look at the introduction of this article, may be helpful to you.

What is SSI?

SSI is an abbreviation for the English server Side includes, translated into Chinese is the server side of the meaning of the inclusion. Technically speaking, SSI is a command or pointer that can be called by a comment line in an HTML file. SSI has powerful features that allow you to update content throughout the site with a simple SSI command, dynamically display time and date, and perform complex functions such as shell and CGI scripting. SSI can be called the best helper for Web developers who are short of money, time-strapped, and heavy-workload.

SSI was originally launched on the NCSA server platform, expanded and enhanced in the Apache server, and is now ready to run on almost all servers. This article will mainly combine Apache server to introduce the use of SSI.

How to start SSI?

Under the Apache server, you can start SSI by directly editing the server configuration file or by creating a. htaccess file in the directory where you need to use SSI. Specifically, the process is as follows:

1. Server configuration file

If the user has access to the server profile, you can start SSI by editing the file access.conf and srm.conf.

First use Telnet to telnet to the server and locate the directory where the configuration files are stored. In general, the Apache server configuration files are stored in the "/usr/local/etc/httpd/conf" directory. Open the file srm.conf using any of the text editors and 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

The comment command line may not be in the user's profile, but only two lines beginning with AddType are found and the "#" symbol at the front of each line is removed.

Save the changes, and then open the file access.conf. The user needs to find the section in the file that sets the DocumentRoot (root file). In general, the text of the paragraph is as follows, but does not exclude $#@60;directory$#@62; and $#@60;/directory$#@62; tags also contain other settings.

# This should is changed to whatever your set DocumentRoot to.
# This may also is "None", "all", or any combination of "Indexes",

Options Indexes FollowSymLinks includes

If the user does not want to execute a script or shell command, you can include the keyword includesnoexec in the options row, which allows SSI, but cannot execute CGI or script commands. (Note: The latest version of the Apache server has only one configuration file httpd.conf, the above mentioned content has been included in the file)

2. Create a file . htaccess

If the user does not have direct access to the server configuration file, you can use the file editor to create a file named. htaccess. Note that you must have the symbol "." Before the file name, so that the server can know that the file is a hidden file, which improves the security of the file and avoids the wrong action. The following three lines of text need to be added to the. htaccess file:

Options Indexes FollowSymLinks includes
AddType application/x-httpd-cgi. Cgi
AddType text/x-server-parsed-html. shtml

After completion, you can upload the. htaccess file to the appropriate directory on the server, which is valid for all subdirectories. If the user wants to disallow CGI or shell commands at the directory level, you can add the keyword includesnoexec to the options row in the. htaccess file.

3. Using the. shtml or. html?

Any files that contain SSI must go through the server parsing process before uploading to the client. While this increases the load on the server to some extent, the performance of a server is not significantly degraded unless the user's site has millions of access users per day. However, if you do not need to use SSI on every page, there is no need for the server to parse each page. If the user only wants to use SSI in several special pages, you can change the suffix name of the file to. shtml so that the server can parse only the. shtml file that contains SSI. On the other hand, if you have multiple pages that use SSI, but users do not want to use the. shtml suffix name, you can use the following command line in the. htaccess file:

AddType text/x-server-parsed-html. html

SSI syntax

SSI follows the following format when it is used:

$#@60;! --#directive parameter= "value"--$#@62;

Where directive is the name of the instruction sent to the server, parameter is the operand of the instruction, and value is the result of the instruction that the user wishes to receive.
All SSI commands are "$#@60;! --# "started, where" $#@60;! -"and" # "can not have any space between, otherwise the server will be called SSI command as a normal file comment processing, will not show any results, and will not produce error. In addition, the "=" in the SSI command cannot have spaces on either side, the value on the right must be enclosed in double quotation marks, followed by a space, and finally the end tag "--$#@62;".

The SSI command contains six major classes of instructions and their respective parameters, as follows:





ErrMsg, timefmt, sizefmt

Virtual, file








cmd, CGI

This news a total of 2 pages, currently on the 1th page 1 2

We will introduce each of them below.

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 front of other SSI commands in the HTML file, otherwise the client can only display the default error message, not the custom information set by the user.

$#@60;! --#config errmsg= "error! please email$#@62;

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

$#@60;! --#config timefmt= "%A,%B%d,%Y"--$#@62;

$#@60;! --#echo var= "last_modified"--$#@62;

The results shown are:

Wednesday, April 12, 2000

Perhaps the user is unfamiliar with the%a%B%d used in the above example, let's summarize some of the more commonly used date and time formats in SSI in tabular form.






% a

Seven-day week abbreviation


< 532651.html true techarticle Have you ever been or are you worried about how you can make changes to a site with thousands of pages in the shortest possible time? Then you can look at the introduction of this article, may be able to you ...

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