Server-Side Includes

 < Day Day Up > 



Server-side includes (SSIs) are designed to provide a much more refined control of your Web site content, namely the Web pages themselves. Server-side includes are Apache directives placed within particular Web pages as part of the page's HTML code. You can configure your Apache Web server to look for SSI directives in particular Web pages and execute them. First, you have to use the Options directive with the include option to allow SSI directives.

Options Includes

You need to instruct the server to parse particular Web pages. The easiest way to enable parsing is to instruct Apache to parse HTML files with specified extensions. Usually, the extension .shtml is used for Web pages that have SSI directories. In fact, in the default Apache configuration files, you can find the following entry to enable parsing for SSI directives in HTML files. The AddType directive here adds the .shtml type as an HTML type of file, and the AddHandler directive specifies that .shtml files are to be parsed (server-parsed).

# To use server-parsed HTML files AddType text/html .shtml AddHandler server-parsed .shtml

Instead of creating a separate type of file, you can use the XBitHack directive to have Apache parse any executable file for SSI directives. In other words, any file with execute permission (see Chapter 28) will be parsed for SSI directives.

SSI directives operate much like statements in a programming language. You can define variables, create loops, and use tests to select alternate directives. An SSI directive consists of an element followed by attributes that can be assigned values. The syntax for a SSI directive is shown here:

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

You can think of an element as operating much like a command in a programming language and attributes as its arguments. For example, to assign a value to a variable, you use the set element with the variable assignment as its attribute. The if directive displays any following text on the given Web page. The if directive takes as its attribute expr, which is assigned the expression to test. The test is able to compare two strings using standard comparison operators such as <=, !=, or =. Variables used in the test are evaluated with the $ operator.

<!--#set myvar="Goodbye" --> <!--#if expr="$myvar = Hello" -->

Other helpful SSI elements are exec, which executes CGI programs, or shell commands, which read the contents of a file into the Web page and also execute CGI files. The echo element displays values such as the date, the document's name, and the page's URL. With the config element, you can configure certain values, such as the date or file size.



 < Day Day Up > 



Red Hat(c) The Complete Reference
Red Hat Enterprise Linux & Fedora Edition (DVD): The Complete Reference
ISBN: 0072230754
EAN: 2147483647
Year: 2004
Pages: 328

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