sHTML Complete Tutorial

Source: Internet
Author: User
Tags add execution file size header variables string version variable
Tutorial |shtml

What is SHTML

Using the HTML file name extension for SSI (server Side include), SSI (server Side include), commonly referred to as "servers-side embedding" or "server-side inclusion," is an ASP-like server-based Web-making technology.

How SSI works:

Before you send content to the browser, you can use the server side include (SSI) directive to include text, graphics, or application information in a Web page. 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 text or graphics that repeats in multiple files, using the include file is an easy way to do so. Save the content in a containing file without having to enter the content into all the 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. Also, when you use the Include file, all changes to the content can be done in just 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 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 directives used to include files, you can 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, effective way to solve this problem, it will be the basic structure of a Web site in a few simple HTML files (templates), we have to do is to upload text to the server, so that the program to follow the template to automatically generate Web pages, so that the management of large Web sites becomes easier.

Therefore, the use of the shtml format of the page is similar to the ASP, but because it is the API is faster, more efficient, faster than the ASP, slower than the HTML, but because you can use the server side contains, so make the page update easy (especially batch update banner, copyright, etc.), imagine it, You have a section of HTML, to insert some special server script in the middle, such as inserting other HTML paragraphs, you choose ASP to complete the task, but if the task is heavier, need more time, such as 5 s, this time you do not use ASP and SHTML, perhaps processing time is only 4s.

What's the use of SSI?

The reason to pull to SSIis because of the acronym for shtml-server-parsed HTML . Contains HTML text with the embedded server side containing the command. The server will read, analyze, and modify the SHTML document completely before being sent to the browser. sHTML and ASP are similar, in shtml named files, using some of the SSI instructions, as in the ASP instructions, you can write SSI instructions in the shtml file, when the client access to these shtml files, the server side will read and interpret these shtml files, Explain the SSI instructions contained in the shtml file, for example: You can use SSI directives in shtml files to refer to other HTML files (#include), and the files that the server sends to the client are explained shtml do not have SSI directives. It implements the HTML does not have the function, is may realize the dynamic shtml, can say is an HTML evolution. Like Sina's news system is like this, the news content is fixed, but its above advertisement and the menu and so on is uses the #include reference to come in.

At present, there are mainly the following types of uses:

    1. Display server-side environment variables < #echo >
    2. Inserts text content directly into the document < #include >
    3. Display information related to Web documents < #flastmod #fsize > (such as file date/size, etc.)
    4. Direct execution of various programs on the server < #exec > (such as CGI or other executable programs)
    5. Set SSI Information display format < #config > (such as file date/size display)

The advanced ssi 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:

is an SSI instruction that copies the contents of the "info.htm" to the current page and, when visitors come to browse, sees the contents of the info.htm in the same way as other HTML documents. Other SSI instructions use the same form as the previous example, see SSI use is only a little bit of code, the use of the form is very simple. Of course, if the Web server does not support SSI, it simply skips over its content as a comment, and the browser ignores that 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 an extension that has been mapped to an SSI interpreter; otherwise, the Web server will not process the SSI directive; By default, the extension. stm,. shtm and. sHTML is 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, you can use SSI scams to download a Perl script to http://sw.cse.bris.ac.uk/WebTools/fakessi.html , Allows your CERN server to use some SSI directives. (Exec directives are not supported.) )

SSI Instruction Basic Format

Program code:

Description

    1. is a comment in HTML syntax that is ignored when the Web server does not support SSI.
    2. #include is one of the SSI directives.
    3. File is an include parameter, info.htm is the parameter value, and the name of the document to be included in this instruction.

Attention:

    1. There is no space between the

      Example:

      This document name
      now time
      Your IP address

      #include demonstration

      Action: Inserts the contents of a text file directly into the document page.

      Grammar:


      The file file name is a relative path that corresponds to the directory where the document using the #include directive resides. The included file can be in the same level of directory or its subdirectories, but not in the previous level directory. File= "nav_head.htm", such as the nav_head.htm document that represents the current directory.
      The virtual file name is the full path to the dummy directory on the Web site. For example, the Nav_head.htm file that represents the Hoyi directory under the root directory of the server document; 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:

        1. The file name must have an extension.
        2. The included files can have any file name extensions, and I think it is most convenient to use the HTM extension directly, and Microsoft recommends using the. inc extension (which depends on your hobby).

      Example:


      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:

      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 the input of a regular application, depending on whether you use the parameter cmd or CGI.

      Grammar:


      Parameters:

      cmd general application
      CGI CGI Script Program

      Example:

      will display the password file
      will display a list of files in the current directory
      will execute CGI program gb.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:

        1. Apache, delete the "options Includes execcgi" code in access.conf;
        2. 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:



      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


      Display file size in kilobytes

      Grammar:


      Show time in a specific time format


      show today is the day of the week, a few months, time zone

      Xssi

      Xssi (Extended SSI) is a set of advanced SSI instructions that are built into the Apache 1.2 or later Mod-include modules. The available directives are:

      #printenv
      #set
      #if

      #printenv

      Role: Displays all environment variables that currently exist in the Web server environment.

      Grammar:

      #set

      Function: You can assign a value to a variable for subsequent if statements.

      Grammar:

      Example:

      #if

      Function: Create a page that can change the data, which is displayed according to the requirements calculated when using the IF statement.

      Grammar:


      Display content

      Display content

      Display content

      Example:


      Welcome to Http://www.baidu.com

      Welcome to Http://www.google.com

      Welcome to Afly ' s blog!

      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 front of the 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.

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


      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 date and time formats in SSI in tabular form.

      sizefmt: Determines whether the file size is expressed in bytes, kilobytes, or megabytes. If the parameter value is "bytes" in bytes, the abbreviation 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.


      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. You can update the entire site in an instant by simply changing one file with the Include command!

      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.


      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:


      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 we can combine the domain name of the website with the SSI command to display the complete URL, namely:

      http://yourdomain

      query_string_unescaped: Displays the query string sent by the client without escaping processing, where all the special characters are preceded by an escape character "\". For example:

      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:


      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:

      last_modified: Displays the last update time for the current document. Again, this is a very useful feature of SSI, as long as you add the following simple text to the HTML document, you can dynamically display the update time on the page.

      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:

      SERVER_NAME: Displays the server's host name, DNS alias, or IP address. For example:

      Server_protocol: Displays the protocol name and version used by the client request, such as http/1.0. For example:

      Server_port: Displays the server's response port. For example:

      Request_method: Displays the client's document request methods, including get, head, and post. For example:

      Remote_host: Displays the name of the client host that sent the request information.

      REMOTE_ADDR: Displays the client IP address that sent the request information.

      Auth_type: The authentication method that displays the user's identity.

      Remote_user: Displays the account name used by the user accessing the protected page.

      4, Fsize: Display the size of the specified file, you can combine the config command sizefmt parameters to customize the output format.

      5, Flastmod: Display the last modified date of the specified file, you can combine the config command timefmt parameters to control the output format.


      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:


      File

      another file

      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 program in the server-side Cgi-bin directory to place a counter on each page:

      About the difference between shtml and HTML

      Let's take a look at the difference between SHTML and HTML, if you explain it in one sentence: SHTML is not HTML but a server api,shtml is the dynamically produced HTML of the server.

      While both are hypertext formats, shtml is a file for SSI technology. That is, the server Side Include--ssi contains instructions. If the Web server has SSI capabilities, most, especially unix-based platform-based Web servers, such as Netscape Enterprise Server, support SSI commands.



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.