SSI usage detail_php tutorial

Source: Internet
Author: User
Tags echo command
SSI usage details. Have you ever been or are you worried about how to modify a website containing thousands of pages in the shortest time? So let's take a look at the introduction in this article. maybe you are worried about whether you have or are trying to complete the modification to a website containing thousands of pages in the shortest time? So you can take a look at the introduction of this article, which may be helpful to you.

What is SSI?

SSI is the abbreviation of Server Side encryption Des. Technically speaking, SSI is a command or pointer that can be called through the annotation line in an HTML file. SSI has powerful functions. you only need to use a simple SSI command to update the content of the entire website, dynamically display the time and date, and execute complicated functions such as shell and CGI scripts. SSI can be called the best helper for website developers who have a shortage of funds, time shortage, and heavy workload.

SSI was initially launched on the NCSA server platform and has been expanded and enhanced on Apache servers. it can now run on almost all servers. This document describes how to use SSI based on the Apache server.


How to Start SSI?

On the Apache server, you can directly edit the server configuration file or create a. htaccess file in the directory where SSI is needed to start SSI. Specifically, the process is as follows:


1. server configuration file

If you have access to the server configuration file, you can edit the file access. conf and srm. conf to start SSI.

First, use Telnet to remotely log on to the server and find the directory where the configuration file is stored. Generally, the configuration files of the Apache server are stored in the "/usr/local/etc/httpd/conf" directory. Open the srm. conf file in any text editor and find the following lines:

# If you want to use server side except Des, or CGI outside
# ScriptAliased directories, uncomment the following lines.
# AddType text/x-server-parsed-html. shtml

# AddType application/x-httpd-CGI. CGI

The preceding annotation command line may not exist in the configuration file, but you only need to find the two lines starting with AddType and remove the '#' symbol at the beginning of each line.

Save the modification, and then open the file access. conf. You need to find the part that sets DocumentRoot in the file. The text of this section is as follows, but is not excluded. And Tags also contain other settings.

# This shoshould be changed to whatever you set DocumentRoot.

# This may also be "None", "All", or any combination of "Indexes ",
Options Indexes FollowSymLinks Includes


If you do not want to execute a script or shell command, you can add the keyword IncludesNOEXEC to the options option line, so that you can promise SSI, but cannot execute CGI or script commands. (Note: The Apache server of the latest version has only one configuration file httpd. conf. all the above mentioned content has been included in this file)

2. create a file. htaccess

If you cannot directly access the server configuration file, you can use the file editor to create a file named. htaccess. Note that the file name must be preceded by the symbol "." so that the server can know that the file is a hidden file, so as to improve file security and avoid wrong operations. Add the following three lines of text to the. htaccess file:

Options Indexes FollowSymLinks Includes
AddType application/x-httpd-CGI. CGI
AddType text/x-server-parsed-html. shtml

After that, you can upload the. htaccess file to the corresponding directory on the server. This file is valid for all subdirectories. If you want to disable CGI or shell commands at the directory level, you can add the keyword IncludesNOEXEC to the Options option line in the. htaccess file.

3.use .shtmlor .html?

Any file containing SSI must go through the parsing process of the server before it is uploaded to the client. Although this will increase the server load to some extent, the performance of a server will not decrease unless the user's website has millions of users accessing it every day. However, if you do not need to use SSI on every page, there is indeed no need for the server to parse every page. Hosts file. On the other hand, if ssiis is used for multiple pages, but the user does not want to use the suffix of .shtml, the following command line can be used in the. htaccess file:

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


SSI syntax

SSI follows the following format during use:



Specifically, directive is the command name sent to the server, parameter is the operation object of the command, and value is the command processing result that the user wants.
All SSI commands use

To organize site content more rationally, you can create the "des" subdirectory under the root directory to store all the contained files. The Virtual parameter notifies the server that it contains a Virtual file, that is, the file and the file being parsed are not in the same directory, but stored in other directories. The server finds the des sub-directory under the root directory based on the value of this parameter. In this way, you can put all the files contained in HTML documents in one directory, and store different pages in different directories or subdirectories according to their relationships. No matter which document is parsed by the server, you can find the contained file without any errors.

However, there is a small problem to solve. Generally, we add some TITLE and META tags to the page. if we require that all pages call the same header file, it is not flexible. When you encounter such a problem, you can use two files that contain the TITLE tag, one for the content before the TITLE tag, and the other for the part after the META tag, you can add any custom content between two contained files. For example:


Your Page Title





Place the page content here



We can see that adding headers and footers to a page can greatly reduce the workload of site updates. But what if we want to dynamically display some content, such as the last update time of the page? You can save the included files with the suffix ".html" so that you can call other included files in the included files.

File:? The relative path of the current directory, where "../" cannot be used or an absolute path. For example:

  

In this case, each directory contains a header.html file. Of course, using this method is not much easier than updating each page, but it is very convenient if you only update one or two files. For example, if we don't want a person who is not familiar with HTML to directly modify the news page on the website, we can just ask him to update a separate text file, then, the file will be included in the HMTL document, so that the original page will not be damaged and the content will be updated at the same time.


3. Echo:

The Echo command displays the following environment variables:

DOCUMENT_NAME: displays the name of the current document.

  

The result is as follows:

Index.html

DOCUMENT_URI: displays the virtual path of the current document. For example:

  

The result is as follows:

/YourDirectory/YourFilename.html

With the continuous development of websites, those longer and longer URLs will be a headache. If SSI is used, everything will be solved. Because we can combine the website domain name with the SSI command to display the complete URL, that is:

Http: // YourDomain

QUERY_STRING_UNESCAPED: displays unescaped query strings sent by the client. all the special characters are preceded by the escape character "". For example:

  

DATE_LOCAL: displays the date and time when the server sets the time zone. You can combine the timefmt parameter of the config command to customize the output information. For example:

  
  

The result is as follows:

Saturday, the 15 of each L, in the year 2000
DATE_GMT: Similar to DATE_LOCAL, but returns a date based on Greenwich Mean Time. For example:

  

LAST_MODIFIED: displays the last update time of the current document. Similarly, this is a very real rose capsule in SSI. why? Gray?


Why? So you can take a look at the introduction of this article, maybe you can...

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.