Server-Side Includes

Server-side includes (SSI) are a wonderful device for saving time and space in web page design. [1] SSI are placeholders that dynamically include data within your page as the server parses the file. Here's the syntax of an SSI command:

[1] Apache Software Foundation, "Apache Tutorial: Introduction to Server-Side Includes" [online], (Forest Hill, MD: Apache Software Foundation, 2002 [cited 13 November 2002]), available from the Internet at http://httpd.apache.org/docs-2.0/howto/ssi.html.
 <!--#element attribute="value" --> 

The element is a predefined SSI function, like echo , exec , or include , that uses the attribute and value parameters. You can include and change snippets of HTML site-wide with one SSI in each page. You also can add optimized dynamic content with SSI based on time or browser characteristics. That's where XSSI comes in.

Conditional SSI

With eXtended Server-Side Includes (XSSI), available in Apache 1.2 and above, Apache added the ability to include conditional logic within your pages, based on environment variables set by the server or within the HTML page itself. Conditional if/else logic adds "flow control" to your pages, allowing you to jazz up your sitewith browser-dependent content, randomized links or messages, and timestamps in various formatsand ultimately create modularized pages. [2]

[2] Webmonkey, "HotWired's XSSI Extensions" [online], (Waltham, MA: Terra Lycos, 1999), available from the Internet at http://hotwired.lycos.com/webmonkey/99/10/index0a.html.

Here is a simple example:

 <!--#if expr="${HTTP_USER_AGENT}= /Mac/" -->      Mac code goes here <!--#else -->     Non-Mac code goes here <!--#endif --> 

Setting and Testing Environment Variables

The CGI specification introduced the notion of a standard set of environment variables that are used to communicate between servers and CGI scripts. [3] Environment variables include SERVER_NAME , QUERY_STRING , and CONTENT_LENGTH . In addition, the server sets environment variables based on the headers received from the client, prefixed with the string HTTP_ . [4] The HTTP_USER_AGENT string holds information about the client requesting the resource from the server (browser, version, and platform). For example, for Internet Explorer 5.0 on my Macintosh PowerBook, the HTTP_USER_AGENT string looks like this:

[3] NCSA, "The CGI Specification" [online], (Champaign, IL: NCSA, 1995), available from the Internet at http://hoohoo.ncsa.uiuc.edu/cgi/interface.html.
[4] Roy T. Fielding et al., "Hypertext Transfer ProtocolHTTP/1.1," RFC 2616 [online], (Reston, VA: The Internet Society, 1999), available from the Internet at http://www.ietf.org/rfc/rfc2616.txt. Defines the HTTP 1.1 protocol for "stateless" web server software. Also specifies what header information is sent from the client to the server.
 Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC) 

You can parse this user agent string to extract information about the client requesting a particular page. Apache extends the standard set of environment variables with their own named variables and gives you the ability to set your own with the set directive. [5]

[5] Apache Software Foundation, "Environment Variables in Apache" [online], (Forest Hill, MD: Apache Software Foundation, 2002 [cited 13 November 2002]), available from the Internet at http://httpd.apache.org/docs-2.0/env.html.
 <!--#set var="isDOM" value="true" --> 

You can use these variables within the same HTML file or automatically pass them to included HTML files to create nested includes. Here is an example:

 <!--#if expr="${HTTP_USER_AGENT} = /Gecko/" -->      <!--#set var="isDOM" value="true" --> <!--#endif --> 

To reference variables, you use the dollar sign ( $ ).To use this new isDOM variable, you would write:

 <!--#if expr="${isDOM}" -->      DOM code goes here <!--#else -->     non-DOM code goes here <!--#endif --> 

Once you've got your variables set up, you can perform comparison operations, like AND (&&) and OR (). Here is an example:

 <!--#if expr="(${isIE5} && ${isMAC})" --> 

You can see where this is going: server-side browser sniffing.

 



Speed Up Your Site[c] Web Site Optimization
Speed Up Your Site[c] Web Site Optimization
ISBN: 596515081
EAN: N/A
Year: 2005
Pages: 135

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net