?? ch06_02.htm
字號:
<p><tt class="command">printenv</tt><a name="INDEX-1284" /></p></td><td /><td><p>Displays a list of environment variables and their values.</p></td></tr><tr><td><p><tt class="command">set</tt><a name="INDEX-1285" /></p></td><td><p><tt class="command">var</tt></p></td><td><p>Sets the value for a new or existing environment variable; thevariable only lasts throughout the current request (but it isavailable to CGI scripts or other SSI documents included in thisdocument).</p></td></tr><tr><td><p><tt class="command">if, elif</tt><a name="INDEX-1286" /></p></td><td><p><tt class="command">expr</tt></p></td><td><p>Starts conditional.</p></td></tr><tr><td><p><tt class="command">else</tt><a name="INDEX-1287" /></p></td><td /><td><p>Starts the "else" part of the conditional.</p></td></tr><tr><td><p><tt class="command">endif</tt><a name="INDEX-1288" /></p></td><td /><td><p>Ends conditional.</p></td></tr><tr><td><p><tt class="command">config</tt><a name="INDEX-1289" /></p></td><td /><td><p>Modifies various aspects of SSI.</p></td></tr><tr><td /><td><p><tt class="command">errmsg</tt></p></td><td><p>Default error message.</p></td></tr><tr><td /><td><p><tt class="command">sizefmt</tt></p></td><td><p>Format for size of the file.</p></td></tr><tr><td /><td><p><tt class="command">timefmt</tt></p></td><td><p>Format for date and time.</p></td></tr></table></div><a name="ch06-4-fm2xml" /><div class="sect2"><h3 class="sect2">6.2.3. Environment Variables</h3><p>You can insert the values of <a name="INDEX-1290" /><a name="INDEX-1291" />environment<a name="INDEX-1292" /> <a name="INDEX-1,293" />variables in an otherwise static HTMLdocument. Here is an example of a document that will contain theserver name, the user's remote host, and the current local dateand time:</p><blockquote><pre class="code"><HTML><HEAD> <TITLE>Welcome!</TITLE></HEAD><BODY><H1>Welcome to my server at <!--#echo var="SERVER_NAME"-->...</H1><HR>Dear user from <!--#echo var="REMOTE_HOST"-->,<P>There are many links to various CGI documents throughout the Web,so feel free to explore.<P><HR><ADDRESS>Webmaster (<!--#echo var="DATE_LOCAL"-->)</ADDRESS></BODY></HTML></pre></blockquote><p><a name="INDEX-1294" /><a name="INDEX-1295" />In this example, we usethe<a name="INDEX-1296" /><a name="INDEX-1297" /> <em class="emphasis">echo</em> SSIcommand with the <em class="emphasis">var</em> attribute to display the<a name="INDEX-1298" /> <a name="INDEX-1,299" /><a name="INDEX-1300" />IP name or address of the servingmachine, the remote host name, and the local time. All<a name="INDEX-1301" />environment variables thatare available to CGI programs are also available to SSI directives.There are also a few variables that are exclusively available for usein SSI directives, such as<a name="INDEX-1302" />DATE_LOCAL, which contains the currentlocal time. Another is <a name="INDEX-1303" /> <a name="INDEX-1,304" />DATE_GMT, whichcontains the time in Greenwich Mean Time:</p><blockquote><pre class="code">The current GMT time is: <!--#echo var="DATE_GMT" --></pre></blockquote><p>Here is another example that uses some of these exclusive SSIenvironment variables to output information about the currentdocument:</p><blockquote><pre class="code"><H2>File Summary</H2><HR>The document you are viewing is: <!--#echo var="DOCUMENT_NAME"-->,which you can access it a later time by opening the URL to:<!--#echo var="DOCUMENT_URI"-->.<HR>Document last modified on <!--#echo var="LAST_MODIFIED"-->.</pre></blockquote><p>This will display the <a name="INDEX-1305" /> <a name="INDEX-1,306" />name, URL, and modification time for thecurrent HTML document.</p><p>For a listing of CGI environment variables, refer to <a href="ch03_01.htm">Chapter 3, "The Common Gateway Interface"</a>. <a href="ch06_02.htm#ch06-59530">Table 6-2</a> shows theadditional variables available to SSI pages.</p><a name="ch06-59530" /><h4 class="objtitle">Table 6-2. Additional Variables Available to SSI Pages </h4><table border="1"><tr><th><p>Environment Variable</p></th><th><p>Description</p></th></tr><tr><td><p><a name="INDEX-1307" />DOCUMENT_NAME</p></td><td><p>The current filename</p></td></tr><tr><td><p><a name="INDEX-1308" />DOCUMENT_URI</p></td><td><p>Virtual path to the file</p></td></tr><tr><td><p><a name="INDEX-1309" />QUERY_STRING_UNESCAPED</p></td><td><p>Unencoded query string with all shell metacharacters escaped with"\"</p></td></tr><tr><td><p><a name="INDEX-1310" />DATE_LOCAL</p></td><td><p>Current date and time in the local time zone</p></td></tr><tr><td><p><a name="INDEX-1311" />DATE_GMT</p></td><td><p>Current date and time in GMT</p></td></tr><tr><td><p><a name="INDEX-1312" />LAST_MODIFIED</p></td><td><p>Last modification date and time for the file requested by the browser</p></td></tr></table></div><a name="ch06-20335" /><div class="sect2"><h3 class="sect2">6.2.4. Tailoring SSI Output</h3><p><a name="INDEX-1313" /><a name="INDEX-1314" /><a name="INDEX-1315" /><a name="INDEX-1316" /><a name="INDEX-1317" />The<em class="emphasis">config</em> command allows you to select the mannerin which error messages, file size information, and<a name="INDEX-1318" />date and timeare displayed. For example, if you use the<em class="emphasis">include</em> command to insert a nonexisting file,the server will output a default error message like the following:</p><blockquote><pre class="code">[an error occurred while processing this directive]</pre></blockquote><p>By using the <em class="emphasis">config</em> command, you can modify thedefault error message. If you want to set the message to"[error-contact webmaster]" you can use the following:</p><blockquote><pre class="code"><!--#config errmsg="[error-contact webmaster]" --></pre></blockquote><p>You can also set the file size format that the server uses whendisplaying information with the<em class="emphasis">fsize</em><a name="INDEX-1319" /> command. For example, this command:</p><blockquote><pre class="code"><!--#config sizefmt="abbrev" --></pre></blockquote><p>will force the server to display the file size rounded to the nearestkilobyte (KB) or megabyte (MB). You can use the argument"bytes" to set the display as a byte count:</p><blockquote><pre class="code"><!--#config sizefmt="bytes" --></pre></blockquote><p>Here is how you can change the time format:</p><blockquote><pre class="code"><!--#config timefmt="%D (day %j) at %r" -->My signature was last modified on: <!--#flastmod virtual="/address.html"-->.</pre></blockquote><p>The output will look like this:</p><blockquote><pre class="code">My signature was last modified on: 09/22/97 (day 265) at 07:17:39 PM</pre></blockquote><p><a name="INDEX-1320" /> <a name="INDEX-1,321" /> <a name="INDEX-1,322" />The <tt class="literal">%D</tt>format inserts the current date in <tt class="literal">mm/dd/yy</tt>format, <tt class="literal">%j</tt> inserts the day of the year, and<tt class="literal">%r</tt> the current time in <tt class="literal">hh/mm/ss</tt><tt class="literal">AM|PM</tt> format. <a href="ch06_02.htm#ch06-35093">Table 6-3</a> listsall the data and time formats you can use.</p><a name="ch06-35093" /><h4 class="objtitle">Table 6-3. Time and Date Formats</h4><table border="1"><tr><th><p>Format</p></th><th><p>Value</p></th><th><p>Example</p></th></tr><tr><td><p><tt class="literal">%a</tt></p></td><td><p>Day of the week abbreviation</p></td><td><p>Sun</p></td></tr><tr><td><p><tt class="literal">%A</tt></p></td><td><p>Day of the week</p></td><td><p>Sunday</p></td></tr><tr><td><p><tt class="literal">%b</tt></p></td><td><p>Month name abbreviation</p></td><td><p>Jan</p></td></tr><tr><td><p><tt class="literal">%B</tt></p></td><td><p>Month name</p></td><td><p>January</p></td></tr><tr><td><p><tt class="literal">%d</tt></p></td><td><p>Date</p></td><td><p>01 (<em class="emphasis">not</em> 1)</p></td></tr><tr><td><p><tt class="literal">%D</tt></p></td><td><p>Date as <tt class="literal">%m/%d/%y</tt></p></td><td><p>06/23/95</p></td></tr><tr><td>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -