Home  >  Article  >  Backend Development  >  Detailed explanation of SSI usage_PHP tutorial

Detailed explanation of SSI usage_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:05:42859browse

Have you ever been or are you currently struggling with how to complete modifications to a website containing thousands of pages in the shortest possible time? Then you can read the introduction of this article, it may be helpful to you.

What is SSI?

SSI is the abbreviation of English Server Side Includes. Translated into Chinese, it means server side inclusion. Technically speaking, SSI is a command or pointer in an HTML file that can be called through a comment line. SSI has powerful functions. With a simple SSI command, you can update the content of the entire website, dynamically display time and date, and execute complex functions such as shell and CGI script programs. SSI can be said to be the best helper for website developers who are short of funds, tight on time, and have a heavy workload.

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


How to start SSI?

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


1. Server configuration file

If the user has access to the server configuration file, it can be started by editing the files access.conf and srm.conf SSI.

First, use Telnet to remotely log in to the server and find the directory where the configuration file is stored. Generally speaking, the configuration files of the Apache server are saved in the "/usr/local/etc/httpd/conf" directory. Open the file srm.conf using any text editor 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 user’s configuration file may not have the above comment line , but just find the two lines starting with AddType and remove the "#" symbol at the front of each line.

Save the changes and open the access.conf file again. The user needs to find the section in the file where the DocumentRoot (root file) is set. Generally speaking, the text is as follows, but it is not excluded that there are other setting contents between the and tags.

# This should be changed to whatever you set DocumentRoot to.

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


If the user does not want to execute scripts or shell commands, the keyword IncludesNOEXEC can be added to the options line , 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, and the above mentioned content has been included in this file)

2. Create the file .htaccess

If Users cannot directly access the server configuration file. They can use a file editor to create a file called .htaccess. Note that there must be a symbol "." before the file name, so that the server can know that the file is a hidden file, thereby improving the security of the file and avoiding incorrect operations. 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 corresponding directory on the server. This file is valid for all subdirectories. If the user wishes to disable CGI or shell commands at the directory level, the keyword IncludesNOEXEC can be added to the Options line in the .htaccess file.

3. Use .shtml or .html?

Any file containing SSI must go through the parsing process of the server before being downloaded to the client. Although this will increase the load on the server to some extent, unless the user's website has millions of users visiting it every day, the performance of a certain server will not decrease significantly. However, if you don't need to use SSI on every page, there is really no need to have the server parse every page. If the user only wants to use SSI in a few special pages, he can change the file extension to .shtml so that the server can only parse .shtml files containing SSI. On the other hand, if there are multiple pages using SSI, but the user does not want to use the .shtml suffix, 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 when used:



In order to organize the content of the site more rationally, users can organize the content of the site in the root directory Create the includes subdirectory to store all include 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:


Your Page Title





Place here Page content



From the above we can see that by including the header and page in the page Feet 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:

 

  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.

 

 The displayed result is:

 index.html

 DOCUMENT_URI: Display The virtual path of the current document. For example:

 

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

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:

 

 DATE_LOCAL: Displays the date and time in the server's set time zone. Users can customize the output information by combining the timefmt parameter of the config command. For example:

 
 

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 it returns a date based on Greenwich Mean Time. For example:

 

 LAST_MODIFIED: Displays the last update time of the current document. Again, this is a very solid rose capsule in SSI.


http://www.bkjia.com/PHPjc/445111.html

truehttp: //www.bkjia.com/PHPjc/445111.htmlTechArticleHave you ever or are you wondering how to complete a website with thousands of pages in the shortest possible time? Worried about revisions? Then you can read the introduction of this article, maybe it can help you...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn