SSI Command _php Tips

Source: Internet
Author: User
Tags echo command file size perl script
What is SHTML
The HTML file name extension using SSI (server Side include), SSI (server Side include), commonly referred to as "server-side
Embedded "or" server-side contains "is a kind of ASP-like server-based Web page production technology.
How SSI works:
You can use the server side include (SSI) directive to include text, graphics, or application information to a Web page before you send content to the browser
In For example, you can use SSI to include a time/date stamp, a copyright notice, or a form for a customer to fill out and return. For repeating in multiple files
The text or graphic that appears, using the include file is an easy way to do so. Save the content in a containing file without having to enter the content
All files. You can invoke the include file with a very simple statement that instructs the WEB server to insert content into the appropriate Web page. and
And, when you use the Include file, all changes to the content can be done in one place.
Because files that contain SSI directives require special processing, the SSI file extension must be given to all SSI files. The default extension is
. stm,. shtm and. shtml.
The Web server processes the SSI directives while processing the Web page. When the Web server encounters an SSI directive, inserts the contents of the containing file directly into the
into an HTML Web page. If an SSI directive is included in the include file, insert the file at the same time. In addition to the basic instructions used to include the file
, you can also use SSI directives to insert information about a file, such as the size of a file, or to run an application or shell command.
Site maintenance often encountered a problem is that the structure of the site has been fixed, but in order to update a little content and have to redo a large number of pages.
SSI provides a simple, efficient way to solve this problem by putting the basic structure of a Web site in a few simple HTML files (
Template), all we have to do is upload the text to the server, and let the program automatically generate the Web pages according to the template, so that managing large Web sites becomes
Easy.
Therefore, the use of sHTML format page is similar to the ASP, but because it is the API so faster and more efficient, faster than the ASP
, slower than HTML, but because the server-side contains can be used, so make the page update easy (especially batch update banner, copyright, etc.), want to
Like, you have a section of HTML, to be interspersed with some special server script in the middle, such as inserting other HTML paragraphs, you choose ASP
To complete this task, but if the task is heavier and requires more time, such as 5 s, this time you do not use ASP and SHTML,
Maybe the processing time is only 4s.
What's the use of SSI?
The reason to pull to SSI is because of the acronym for Shtml-server-parsed HTML. Contains embedded server side contains life
The HTML text of the order. The server will read, analyze, and modify the SHTML document completely before being sent to the browser. sHTML
There are some similar to the ASP, in the file named sHTML, using some of the SSI instructions, just like the instructions in ASP, you can shtml file
When the client accesses these shtml files, the server side reads and interprets the shtml files, shtml
The SSI instructions contained in the piece are interpreted as: You can use SSI directives in shtml files to refer to other HTML files (#include)
The file that the carrier sends to the client is the shtml that has been interpreted without SSI directives. It implements the functionality that HTML does not have, which is the ability to implement
The dynamic shtml, which can be said to be an evolution of HTML. Like Sina's news system is like this, the news content is fixed, but it
Ads and menus are used in #include quotes.
At present, there are mainly the following types of uses:
Display server-side environment variables < #echo >
Inserts text content directly into the document < #include >
Display information related to Web documents < #flastmod #fsize > (such as file date/size, etc.)
Direct execution of various programs on the server < #exec > (such as CGI or other executable programs)
Set SSI Information display format < #config > (such as file date/size display)
The advanced ssi<xssi> can set the variable to use the IF condition statement.
Using SSI
SSI is a set of commands provided for Web servers that are embedded directly in the annotation content of an HTML document. Such as:
<!--#include file= "info.htm"-->
is an SSI instruction that copies the contents of "info.htm" to the current page, and when visitors come to see the other
The HTML document displays the contents of the info.htm. Other SSI directives use the same form as just the example, which shows that SSI uses only
is to insert a bit of code, the use of the form is very simple. Of course, if the Web server does not support SSI, it will simply treat it as a comment letter
, skip the content directly, and the browser ignores the information.
How do I configure SSI features on my web server?
On some Web servers (such as IIS 4.0/sambar 4.2), files containing #include directives must use the mapped to SSI interpretation
The extension of the program; otherwise, the WEB server will not process the SSI directive; By default, the extension. stm,. shtm and. sHTML are
Mapped to an interpreter (Ssinc.dll).
Apache is based on your settings, modify srm.conf such as:
AddType text/x-server-parsed-html. sHTML will parse SSI directives only for files with the. shtml extension
AddType text/x-server-parsed-html. HTML will parse SSI directives for all HTML documents
Netscape Web servers use Administration server (Management Server) directly to turn on SSI features.
Website using the Mapping tab in the Server Admin program, the extension Add content type is: Wwwserver/html-ssi
The Cern server does not support SSI, which can be downloaded to the http://sw.cse.bris.ac.uk/WebTools/fakessi.html using SSI scams
A Perl script that allows your CERN server to use some SSI directives. (Exec directives are not supported.) )
SSI Instruction Basic Format
Program code:
<!--directive name = "Instruction parameter" >
Example:
<!--#include file= "info.htm"-->
Description
<!----> is a comment in HTML syntax that is ignored when the Web server does not support SSI.
#include is one of the SSI directives.
File is an include parameter, info.htm is the parameter value, and the name of the document to be included in this instruction.
Attention:
There is no space between the <!--and the # number, only the SSI instruction and the parameters exist between the spaces.
The above punctuation = "", one can not be less.
SSI directives are case sensitive, so parameters must be lowercase to work.
SSI instructions to use the detailed
#echo Demonstration
Action: Inserts environment variables into the page.
Grammar:
<!--#echo var= "variable name"-->
Example:
<!--#echo var= "Document_name"--> This document name
<!--#echo var= "date_local"--> now time
<!--#echo var= "REMOTE_ADDR"--> Your IP address
#include demonstration
Action: Inserts the contents of a text file directly into the document page.
Grammar:
<!--#include file= "file name"-->
<!--#include virtual= "file name"-->
The file file name is a relative path that corresponds to the directory where the document using the #include directive resides. Included files can be in the same
Level directory or its subdirectories, but not in the previous directory. For example, a nav_head.htm document that represents the current directory;
File= "Nav_head.htm".
The virtual file name is the full path to the dummy directory on the Web site. If the representation is relative to the server document root directory under the Hoyi directory.
nav_head.htm file; file= "/hoyi/nav_head.htm"
Parameters:
file specifies the location of the containing file relative to this document
virtual Specifies the location relative to the server document root directory
Attention:
The file name must have an extension.
The included files can have any file name extensions, and I think it is most convenient to use the HTM extension directly, as Microsoft recommends. inc extension
Name (it depends on your hobby).
Example:
<!--#include file= "nav_head.htm" inserts the header file into the current page
<!--#include file= "nav_foot.htm" to insert the tail file into the current page
#flastmod and #fsize Demonstrations
Role:
Date #flastmod file Last updated
Length of #fsize file
Grammar:
<!--#flastmod file= "file name"-->
<!--#fsize file= "file name"-->
Parameters:
file specifies the location of the containing file relative to this document, such as Info.txt, which represents the Info.txt document under the current directory
virtual Specifies the location relative to the server document root directory, as/hoyi/info.txt
Note: The file name must have an extension.
Example:
<!--#flastmod file= "news.htm" inserts the last updated date of the news.htm file in the current directory into the current page
<!--#fsize file= "news.htm"--> the news.htm file size in the current directory to the current page
#exec Demonstration
Action: Inserts the output of an external program into the page. You can insert a CGI program or an input to a regular application, depending on the
parameter is cmd or CGI.
Grammar:
<!--#exec cmd= "file name"-->
<!--#exec cgi= "file name"-->
Parameters:
CMD general application
CGI CGI script program
Example:
<!--#exec cmd= "cat/etc/passwd"--> will display the password file
<!--#exec cmd= "dir/b"--> will display a list of files in the current directory
<!--#exec cgi= "/cgi-bin/gb.cgi"--> will execute CGI program gb.cgi.
<!--#exec cgi= "/cgi-bin/access_log.cgi"--> will execute CGI program access_log.cgi.
Note: As you can see from the example above, this instruction is quite handy, but there are also security issues.
Prohibited method:
Apache, delete the "options Includes execcgi" code in access.conf;
In IIS, to disable the #exec command, you can modify the SSIExecDisable metabase;
#config
Role: Specifies the format for error messages, dates, and file sizes returned to the client browser.
Grammar:
<!--#config errmsg= "Custom error Messages"-->
<!--#config sizefmt= "display units"-->
<!--#config timefmt= "display format"-->
Parameters:
ErrMsg Custom SSI Execution error messages can be done for any way you like.
SIZEFMT file size display, default to byte mode ("bytes") can be changed to kilobytes ("abbrev")
TIMEFMT time display mode, the most flexible configuration properties.
Example: Displays the size of a file that does not exist
<!--#config errmsg= "Server execution error, please contact Administrator yiho@126.com, thank you! "-->
<!--#fsize file= "files that do not exist. htm"-->
Display file size in kilobytes
Grammar:
<!--#config sizefmt= "Abbrev"-->
<!--#fsizefile = "News.htm"-->
Show time in a specific time format
<!--#config timefmt= "%y years/%m months%d days%w Beijing time%h:%m:%s,%y years have passed%j days today is the%y year of the first%u
A Week "-->
<!--#echo var= "date_local"--> show today is the day of the week, a few months, time zone
<!--#config timefmt= "Today%a,%B, server time zone is%z, is"-->
<!--#echo var= "date_local"-->
Xssi
Xssi (Extended SSI) is a set of advanced SSI instructions that are built into the Apache 1.2 or later Mod-include modules. which can be
The instructions used are:
#printenv
#set
#if
#printenv
Role: Displays all environment variables that currently exist in the Web server environment.
Grammar:
<!--#printenv-->
#set
Function: You can assign a value to a variable for subsequent if statements.
Grammar:
<!--#set var= "variable name" value= "Variable Value"-->

Example:
<!--#set var= "color" value= "Red"-->

#if
Function: Create a page that can change the data, which is displayed according to the requirements calculated when using the IF statement.
Grammar:
<!--#if expr= "$ variable name =\" variable value a\ ""-->
Display content
<!--#elif expr= "$ variable name =\" variable value b\ ""-->
Display content
<!--#else-->
Display content
<!--#endif "-->
Example:
<!--#if expr= "$SERVER _name=\" "Hoyi.zb169.net\"-->
Welcome to the good easy CGI factory in Zibo Hotline's branch station http://hoyi.zb169.net.
<!--#elif expr= "$SERVER _name=\" "Linux.cqi.com.cn\"-->
Welcome to the good easy CGI factory in the Sun City's substation Http://linux.cqi.com.cn/~hoyi.
<!--#else-->
Welcome to the good easy CGI factory!
<!--#endif "-->
Note: The backslash used in the preceding instruction is used to replace the inner quotation marks so that they are not interpreted as an ending expression. Can not be omitted.
1. Config command
The Config command is primarily used to modify the default settings for SSI. which
ErrMsg: Sets the default error message. In order to return the user-defined error message normally, the errmsg parameter must be placed in the HTML file
Placed in front of other SSI commands, the client can only display default error messages, not custom information set by the user.
<!--#config errmsg= "error! Please email webmaster@mydomain.com "-->
TIMEFMT: Defines the use format for dates and times. The TIMEFMT parameter must be used before the echo command.
<!--#config timefmt= "%A,%B%d,%Y"-->
<!--#echo var= "last_modified"-->
Display results as:
Wednesday, April 12, 2000
Perhaps the user is unfamiliar with the%a%B%d used in the previous example, so let's summarize some of the more commonly used in SSI in tabular form
Date and time formats.
SIZEFMT: Determines whether the file size is expressed in bytes, kilobytes, or megabytes. If the parameter value is "bytes" in bytes;
Abbreviations can be used for kilobytes and megabytes. Similarly, the SIZEFMT parameter must be placed in front of the fsize command before it can be used.
<!--#config sizefmt= "bytes"-->
<!--#fsize file= "index.html"-->
2. Include command
The Include command inserts text or pictures from other documents into the currently parsed document, which is the key to the entire SSI. Pass
The include command only needs to change a file to instantly update the entire site!
The Include command has two different parameters:
Virtual: gives a dummy path to a document on the server side.
File: Gives the relative path to the current directory, where you cannot use the. /"And you cannot use absolute paths.
<!--#include virtual= "/includes/header.html"-->
<!--#include file= "header.html"--> This requires a header.html file to be included in each directory.
3. Echo command
The Echo command can display the following environment variables:
Document_name: Displays the name of the current document.
Document_uri: Displays the virtual path of the current document. For example:
<!--#echo var= "Document_name"-->
<!--#echo var= "Document_uri"-->
With the development of the Web site, the increasingly long URL address will certainly make people headache. If you use SSI, everything will be solved. Because I
We can combine the domain name of the website with the SSI command to display the complete URL, namely:
http://yourdomain<!--#echo var= "Document_uri"-->
Query_string_unescaped: Displays the query string sent by the client without escaping processing, where all the special characters are preceded by a turn
The literal character "\". For example:
<!--#echo var= "query_string_unescaped"-->
Date_local: Displays the date and time the server set the time zone. The user can combine the timefmt parameters of the config command to customize the output information
。 For example:
<!--#config timefmt= "%A, the%d of%B, in the year%Y"-->
<!--#echo var= "date_local"-->
Display results as:
Saturday, the 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:
<!--#echo var= "Date_gmt"-->
Last_modified: Displays the last update time for the current document. Again, this is a very useful feature in SSI, as long as the HTML document
By adding the following simple text, you can dynamically display the update time on the page.
<!--#echo var= "last_modified"-->
CGI Environment variables
In addition to the SSI environment variables, the echo command can display the following CGI environment variables:
Server_software: Displays the name and version of the Server software. For example:
<!--#echo var= "Server_software"-->
SERVER_NAME: Displays the server's host name, DNS alias, or IP address. For example:
<!--#echo var= "SERVER_NAME"-->
Server_protocol: Displays the protocol name and version used by the client request, such as http/1.0. For example:
<!--#echo var= "Server_protocol"-->
Server_port: Displays the server's response port. For example:
<!--#echo var= "Server_port"-->
Request_method: Displays the client's document request methods, including get, head, and post. For example:
<!--#echo var= "Request_method"-->
Remote_host: Displays the name of the client host that sent the request information.
<!--#echo var= "Remote_host"-->
REMOTE_ADDR: Displays the client IP address that sent the request information.
<!--#echo var= "REMOTE_ADDR"-->
Auth_type: The authentication method that displays the user's identity.
<!--#echo var= "Auth_type"-->
Remote_user: Displays the account name used by the user accessing the protected page.
<!--#echo var= "Remote_user"-->
4, Fsize: Display the size of the specified file, you can combine the config command sizefmt parameters to customize the output format.
<!--#fsize file= "index_working.html"-->
5, Flastmod: Display the last modified date of the specified file, you can combine the config command timefmt parameters to control the output format.
<!--#config timefmt= "%A, the%d of%B, in the year%Y"-->
<!--#flastmod file= "file.html"-->
Here, we can use the Flastmod parameter to display the updated date of all the linked pages on a page. The method is as follows:
<!--#config timefmt= "%B%d,%Y"-->
<a href= "/directory/file.html" >File</A>
<!--#flastmod virtual= "/directory/file.html"-->
<a href= "/another_directory/another_file.html" >another file</a>
<!--#flastmod virtual= "/another_directory/another_file.html"-->
Display results as:
File April 19, 2000
Another File January 08, 2000
6, Exec
The EXEC command can execute CGI scripts or shell commands. Use the following methods:
CMD: Executes the specified string using/bin/sh. If SSI uses the INCLUDESNOEXEC option, the command is masked.
CGI: can be used to execute CGI scripts. For example, the following example uses the counter.pl script in the server-side Cgi-bin directory for each
A page to place a counter:
<!--#exec  cgi= "/cgi-bin/counter.pl"  -->

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.