SSI use Details (ii) _php tutorial

Source: Internet
Author: User
Tags echo command
2.Include Command

The include command can insert text or images from other documents into the currently parsed document, which is the key to the entire SSI. With the include command, you can update an entire site in just one file.

The include command has two different parameters, and if you update the site with the wrong parameters, you will get a whole bunch of error messages instead of the original intention.

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 reasonably, the user can create a includes subdirectory under the root directory to hold all the included files. The virtual parameter informs the server that it is going to contain a dummy file, that is, the file is not in the same directory as the currently parsed document, but is stored in a different directory. The server locates the includes subdirectory under the root directory based on the value of this parameter. Using this method, the user can put all the files contained in the HTML document in a directory, and depending on the relationship between the different pages stored in different directories or subdirectories. Regardless of which document the server resolves, it can find the contained files without generating any errors.

But here's a small problem that needs to be addressed. In general, we will add some title and meta tags to the page, if we specify that all the pages are called the same header file, it is very inflexible. When users encounter such problems, they can use two include files, one to set the content before the title tag, the other to set the META tag, and to add any custom content between the two included 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 by including headers and footers in the page, you can significantly reduce the amount of site updates. But what if we want to show something dynamically, such as when the page was last updated? No problem, we can save the include file using the. html suffix so that other include files can be called in the include file.

File: Give? The relative path of the current directory, where you cannot use the ".. /", nor can you use absolute paths. For example:

$#@60;! --#include file= "header.html"--$#@62;

This requires that a header.html file be included in each directory. Of course, using this method is not as simple as updating each page, but it is convenient if the user only updates one or two files. For example, if we do not want a person who is unfamiliar with HTML to directly change the news page in the site, you can just let him update a separate text file, and then include the file in the HMTL document, so that the original page will not be broken, while updating the content, 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 results shown are:

Index.html

Document_uri: Displays the virtual path of the current document. For example:

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

The results shown are:

/yourdirectory/yourfilename.html

With the development of the website, those increasingly long URLs will certainly make people headache. If you use SSI, everything will be resolved. Because we can combine the domain name of the website with the SSI command to display the complete URL, namely:

http://yourdomain$#@60;! --#echo var= "Document_uri"--$#@62;

query_string_unescaped: Displays the non-escaped query string sent by the client with the escape character "" in front of all the special characters. For example:

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

date_local: Displays the date and time when the server sets the time zone. The user can customize the output information with 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 results shown are:

Saturday, the. April, the year 2000

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


date_gmt: The function is the same as date_local, except that it returns a date that is 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 an SSI in the very real rose capsule Huan rancour δ Fascine Gray atonement tml document with the following line of simple text, you can dynamically display the update time on the page.

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

CGI Environment variables

In addition to the 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 host name, DNS alias, or IP address of the server. 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 sent the request information.

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

remote_addr: Displays the client IP address where the request information is made.

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

Auth_type: Displays the authentication method for the user's identity.

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

Remote_user: Displays the name of the account used by the user who accessed the protected page.

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

4.Fsize: Displays the size of the specified file, which can be customized with the sizefmt parameter of the config command.

$#@60;! --#fsize file= "index_working.html"--$#@62;

5.Flastmod: Displays the last modified date of the specified file, which 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 Flastmod parameter to display the updated 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 results shown are:

File April 19, 2000
Another File January 08, 2000

Perhaps some readers will think that the two links are so complex, not at all convenient. In fact, if there are 20 or more links on the page, and each link is updated periodically, you can see the effect of using Flastmod to display the modified date.

6.Exec

The EXEC command can execute CGI scripts or shell commands. Here's how to use it:

CMD: Executes the specified string using/bin/sh. If SSI uses the INCLUDESNOEXEC option, the command will be masked.

CGI: Can be used to execute CGI scripts. For example, the following example uses the counter.pl script program in the server Cgi-bin directory to place a counter on each page:

$#@60;! --#exec cgi= "/cgi-bin/counter.pl"--$#@62;

This news a total of 2 pages, currently on the 2nd Page 1 2


http://www.bkjia.com/PHPjc/532650.html www.bkjia.com true http://www.bkjia.com/PHPjc/532650.html techarticle The 2.Include command include command can insert text or images 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 a text ...

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