⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 693-695.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Special Edition Using Linux, Fourth Edition:Configuring Apache</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0789717468//-->

<!--TITLE=Special Edition Using Linux, Fourth Edition//-->

<!--AUTHOR=Jack Tackett//-->

<!--AUTHOR=Jr.//-->

<!--AUTHOR=Steve Burnett//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Que//-->

<!--CHAPTER=36//-->

<!--PAGES=693-695//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="690-693.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="695-697.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading10"></A><FONT COLOR="#000077">Server-Side Includes</FONT></H4>

<P><I>Server-side includes</I> are best described as a preprocessing language for HTML. The &#147;processing&#148; takes place on the server side. As such, visitors to your site never need to know that you use server-side includes, and thus they require no special client software. The format of these includes looks something like the following:</P>

<!-- CODE SNIP //-->

<PRE>

&lt;!--#<I>directive attribute ="value"</I> --&gt;

</PRE>

<!-- END CODE SNIP //-->

<P>Sometimes a given &#147;directive&#148; can have more than one attribute at the same time. The funky syntax is due to the desire to hide this functionality within an SGML comment&#151;that way, your regular HTML validation tools will work without having to learn new tags or anything. The syntax is important; leaving off the final <TT>--</TT>, for example, will result in errors.</P>

<P><FONT SIZE="+1"><B>#include</B></FONT></P>

<P>The <TT>#include</TT> directive is probably the most commonly used. You use it to insert another HTML file into the HTML document. The allowed attributes for <TT>#include</TT> are <TT>virtual</TT> and <TT>file</TT>. The functionality of the <TT>file</TT> attribute is a subset of that provided by the <TT>virtual</TT> attribute, and it exists mostly for backward compatibility, so its use isn&#146;t recommended.</P>

<P>The <TT>virtual</TT> attribute tells the server to treat the value of the attribute as a request for a relative link&#151;meaning that you can use ../ to locate objects above the directory and that other transformations, such as <TT>Alias</TT>, will apply. Here&#146;s an example of such:</P>

<!-- CODE SNIP //-->

<PRE>

&lt;!--#include virtual="quote.txt" --&gt;

&lt;!--#include virtual="/toolbar/footer.html" --&gt;

&lt;!--#include virtual="../footer.html" --&gt;

</PRE>

<!-- END CODE SNIP //-->

<P><FONT SIZE="+1"><B>#exec</B></FONT></P>

<P>The <TT>#exec</TT> directive is used to run a script on the server side and insert its output into the SSI (server-side includes) document being processed. There are two choices: executing a CGI script by using the <TT>cgi</TT> attribute or executing a shell command by using the <TT>cmd</TT> attribute. For example,</P>

<!-- CODE SNIP //-->

<PRE>

&lt;!--#exec cgi="counter.cgi" --&gt;

</PRE>

<!-- END CODE SNIP //-->

<P>takes the output of the CGI program counter.cgi and inserts it into the document.

</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>The CGI output still has to include the <TT>"text/html"</TT> content-type header; otherwise, an error will occur.<HR></FONT>

</BLOCKQUOTE>

<P>Likewise,

</P>

<!-- CODE SNIP //-->

<PRE>

&lt;!--#exec cmd="ls -l" --&gt;

</PRE>

<!-- END CODE SNIP //-->

<P>takes the output of a call to <TT>ls -l</TT> in the document&#146;s directory and inserts it into the output page as a replacement for the <TT>#exec</TT> command. Like the <TT>file</TT> attribute for the <TT>#include</TT> directive, this type of <TT>#exec</TT> command is mostly for backward compatibility, because it&#146;s something of a security hole in an untrusted environment.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>There are definitely security concerns with allowing users access to CGI functionality and even greater concerns with <TT>#exec cmd</TT>, such as

<!-- CODE SNIP //-->

<PRE>

   cmd="cat /etc/passwd"

</PRE>

<!-- END CODE SNIP //-->

<P>If a site administrator wants to let users use server-side includes but not use the <TT>#exec</TT> directive, he or she can set <TT>IncludesNOEXEC</TT> as an option for the directory in the access configurations.<HR></FONT>

</BLOCKQUOTE>

</P>

<P><FONT SIZE="+1"><B>#echo</B></FONT></P>

<P>The <TT>#echo</TT> directive has one attribute&#151;<TT>var</TT> &#151;whose value is any CGI environment variable as well as a small list of other variables, as shown in Table 36.3.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 36.3</B> Values for the var Attribute

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="20%" ALIGN="LEFT">Attribute

<TH WIDTH="80%" ALIGN="LEFT">Definition

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD><TT>DATE_GMT</TT>

<TD>The current date in Greenwich Mean Time.

<TR>

<TD><TT>DATE_LOCAL</TT>

<TD>The current date in the local time zone.

<TR>

<TD VALIGN="TOP"><TT>DOCUMENT_NAME</TT>

<TD>The file system name of the SSI document, not including the directories below it.

<TR>

<TD VALIGN="TOP"><TT>DOCUMENT_URI</TT>

<TD>URI stands for <I>Uniform Resource Identifier</I>. In a Uniform Resource Locator (URL) of the format <A HREF="http://host/path/file">http://host/path/file</A>, the URI is the /<I>path</I>/<I>file</I> part.

<TR>

<TD><TT>LAST_MODIFIED</TT>

<TD>The date the SSI document was modified.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P>For example, the command

</P>

<!-- CODE SNIP //-->

<PRE>

&lt;!--#echo var="DATE_LOCAL" --&gt;

</PRE>

<!-- END CODE SNIP //-->

<P>inserts something along the lines of <TT>Wednesday, 05-Mar-97 10:44:54 GMT</TT> into the document.</P>

<P><FONT SIZE="+1"><B>#fsize, #flastmod</B></FONT></P>

<P>The <TT>#fsize</TT> and <TT>#flastmod</TT> directives print out the size and the last-modified date, respectively, of any object given by the URI listed in the <TT>file</TT> or <TT>virtual</TT> attribute, as in the <TT>#include</TT> directive. For example, this command</P>

<!-- CODE SNIP //-->

<PRE>

&lt;!--#fsize file="index.html" --&gt;

</PRE>

<!-- END CODE SNIP //-->

<P>returns the size of the index.html file in that directory.

</P>

<P><FONT SIZE="+1"><B>#config</B></FONT></P>

<P>You can modify the rendering of certain SSI directives by using the <TT>#config</TT> directive. The <TT>sizefmt</TT> attribute controls the rendering of the <TT>#fsize</TT> directive with values of <TT>bytes</TT> or <TT>abbrev</TT>. The exact number of bytes is printed when <TT>bytes</TT> is given, whereas an abbreviated version of the size (in KB for kilobytes or MB for megabytes) is given when <TT>abbrev</TT> (the default) is set. For example, a snippet of SSI HTML like</P>

<!-- CODE SNIP //-->

<PRE>

&lt;!--#config sizefmt="bytes" --&gt;

The index.html file is &lt;!--#fsize virtual="index.html" --&gt; bytes

</PRE>

<!-- END CODE SNIP //-->

<P>returns <TT>The index.html file is 4,522 bytes</TT>. Meanwhile,</P>

<!-- CODE SNIP //-->

<PRE>

&lt;!--#config sizefmt="abbrev" --&gt;

</PRE>

<!-- END CODE SNIP //-->

<P>returns <TT>The index.html file is 4K bytes</TT>.</P>

<P>The <TT>timefmt</TT> directive controls the rendering of the date in the <TT>DATE_LOCAL</TT>, <TT>DATE_GMT</TT>, and <TT>LAST_MODIFIED</TT> values for the <TT>#echo</TT> directive. It uses the same format as the <TT>strftime</TT> call. (In fact, the server does call <TT>strftime</TT>, a system call that formats the time in a string of specified length.) The string format consists of variables that begin with <TT>%</TT>. For example, <TT>%H</TT> is the hour of the day, in 24-hour format. For directions on how to construct a <TT>strftime</TT> -format date string, consult <TT>strftime</TT> &#146;s man page for a list of variables.</P>

<P>An example might be</P>

<!-- CODE SNIP //-->

<PRE>

&lt;!--#config timefmt="%Y/%m/%d-%H:%M:%S" --&gt;

</PRE>

<!-- END CODE SNIP //-->

<P>with the resulting date string for Jan. 2, 1997, at 12:30 in the afternoon as

</P>

<!-- CODE SNIP //-->

<PRE>

1997/01/02-12:30:00

</PRE>

<!-- END CODE SNIP //-->

<P>Finally, the last attribute the <TT>#config</TT> directive can take is <TT>errmsg</TT>, which is simply the error to print out if there are any problems parsing the document. For example, the right default is</P>

<!-- CODE SNIP //-->

<PRE>

&lt;!--#config errmsg="An error occurred while processing this directive" --&gt;

</PRE>

<!-- END CODE SNIP //-->

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="690-693.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="695-697.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -