DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> CSS入門知識 >> CSS詳解 >> SSI技術—SHTML(生成靜態時用的最火)
SSI技術—SHTML(生成靜態時用的最火)
編輯:CSS詳解     

什麼是shtml SHTML語法 SHtml教程 格式 編寫 技術

使用SSI (Server Side Include)技術

想要找到既富有創意的平面設計人員,又有腳本開發經驗的人員,實在是太難了。而如果一個百分之百的頁面都是php腳本的網站,將為頁面維護帶來非常大的困難。而且使用了PHP的自動加頭和加尾的方法,使得幾乎所有頁面都是語義不完整的,不能借助任何一款頁面設計工具工作,是另一個弊病。

利用SSI技術,可以有效的將HTML網頁和CGI腳本邏輯上分開,也可以將重復的Html元素抽象和獨立出來,減輕維護負擔。

SSI (Server Side Includes) are directives that are placed in HTML pages, and evaluated on the server while the pages are being served. They let you add dynamically generated content to an existing Html page, without having to serve the entire page via a CGI program, or other dynamic technology.

 

全文:

 

配置Apache,支持SSI# This tells apache that you want to permit files to# be parsed for SSI directives.Options +Includes
# At Linux or unix can use#  Options +Includes -IncludesNOEXEC# win32 not use it
# You have to tell apache which files should be parsed.AddType text/html .shtmlAddHandler server-parsed .sHtml
 


 

SSI語法

 

Basic SSI directives Syntax

<!--#element attribute=value attribute=value ... -->
 

Today's date

<!--#config timefmt="%Y/%m/%d %a %H:%M:%S" -->Today is <!--#echo var="DATE_LOCAL" -->
 

Modification date of the file

This document last modifIEd <!--#flastmod file="index.Html" -->
 

Including the results of a CGI program

<!--#include virtual="/cgi-bin/counter.pl" --><!--#include virtual="/cgi-bin/example.CGI?argument=value" -->
 

You can use "#exec CGI=" directive, but it can be disabled using the IncludesNOEXEC Option.

Including a standard footer

<!--#include virtual="/footer.Html" -->
 

Executing commands

<!--#exec cmd="ls" -->
 

This feature is dangerous. You can allow SSI, but not the exec feature, with the IncludesNOEXEC argument to the Options directive.

Setting variables

<!--#set var="modified" value="$LAST_MODIFIED" --><!--#set var="date" value="${DATE_LOCAL}_${DATE_GMT}" -->
 

Conditional expressions

<!--#if expr="test_condition" --><!--#elif expr="test_condition" --><!--#else --><!--#endif -->
 

1、Config命令

  Config命令主要用於修改SSI的默認設置。其中:

  Errmsg:設置默認錯誤信息。為了能夠正常的返回用戶設定的錯誤信息,在Html文件中Errmsg參數必須被放置在其它SSI命令的前面,否則客戶端只能顯示默認的錯誤信息,而不是由用戶設定的自定義信息。

    <!--#config errmsg="Error! Please email [email protected] --> 

  Timefmt:定義日期和時間的使用格式。Timefmt參數必須在echo命令之前使用。

    <!--#config timefmt="%A, %B %d, %Y"-->
    <!--#echo var="LAST_MODIFIED" -->

  顯示結果為:
    
    Wednesday, April 12, 2000 

  也許用戶對上例中所使用的%A %B %d感到很陌生,下面我們就以表格的形式總結一下SSI中較為常用的一些日期和時間格式。 www.domain.com

  Sizefmt:決定文件大小是以字節、千字節還是兆字節為單位表示。如果以字節為單位,參數值為"bytes";對於千字節和兆字節可以使用縮寫形式。同樣,sizefmt參數必須放在fsize命令的前面才能使用。

    <!--#config sizefmt="bytes" -->
    <!--#fsize file="index.Html" --> 

  2、Include命令

  Include命令可以把其它文檔中的文字或圖片插入到當前被解析的文檔中,這是整個SSI的關鍵所在。通過Include命令只需要改動一個文件就可以瞬間更新整個站點!

  Include命令具有兩個不同的參數:

  Virtual:給出到服務器端某個文檔的虛擬路徑。例如:

    <!--#include virtual="/includes/header.Html" --> 

  File:給出到當前目錄的相對路徑,其中不能使用"../",也不能使用絕對路徑。例如:

    <!--#include file="header.Html" -->

  這就要求每一個目錄中都包含一個header.Html文件。

  3、Echo命令

  Echo命令可以顯示以下各環境變量:

  DOCUMENT_NAME:顯示當前文檔的名稱。

    <!--#echo var="DOCUMENT_NAME" -->

顯示結果為:

    index.Html

  DOCUMENT_URI:顯示當前文檔的虛擬路徑。例如:

    <!--#echo var="DOCUMENT_URI" -->

  顯示結果為:

    /YourDirectory/YourFilename.Html 

  隨著網站的不斷發展,那些越來越長的URL地址肯定會讓人頭疼。如果使用SSI,一切就會迎刃而解。

 

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved