📄 mod_include.html.en
字号:
using the query string, this cannot be done with <code>exec cgi</code>, but can be done with <code>include virtual</code>, as shown here:</p> <div class="example"><p><code> <!--#include virtual="/cgi-bin/example.cgi?argument=value" --> </code></p></div> </dd> <dt><code>cmd</code></dt> <dd><p>The server will execute the given string using <code>/bin/sh</code>. The <a href="#includevars">include variables</a> are available to the command, in addition to the usual set of CGI variables.</p> <p>The use of <code><a href="#includevirtual">#include virtual</a></code> is almost always prefered to using either <code>#exec cgi</code> or <code>#exec cmd</code>. The former (<code>#include virtual</code>) uses the standard Apache sub-request mechanism to include files or scripts. It is much better tested and maintained.</p> <p>In addition, on some platforms, like Win32, and on unix when using <a href="../suexec.html">suexec</a>, you cannot pass arguments to a command in an <code>exec</code> directive, or otherwise include spaces in the command. Thus, while the following will work under a non-suexec configuration on unix, it will not produce the desired result under Win32, or when running suexec:</p> <div class="example"><p><code> <!--#exec cmd="perl /path/to/perlscript arg1 arg2" --> </code></p></div> </dd> </dl> <h3><a name="element.fsize" id="element.fsize">The fsize Element</a></h3> <p>This command prints the size of the specified file, subject to the <code>sizefmt</code> format specification. Attributes:</p> <dl> <dt><code>file</code></dt> <dd>The value is a path relative to the directory containing the current document being parsed.</dd> <dt><code>virtual</code></dt> <dd>The value is a (%-encoded) URL-path. If it does not begin with a slash (/) then it is taken to be relative to the current document. Note, that this does <em>not</em> print the size of any CGI output, but the size of the CGI script itself.</dd> </dl> <h3><a name="element.flastmod" id="element.flastmod">The flastmod Element</a></h3> <p>This command prints the last modification date of the specified file, subject to the <code>timefmt</code> format specification. The attributes are the same as for the <code><a href="#element.fsize">fsize</a></code> command.</p> <h3><a name="element.include" id="element.include">The include Element</a></h3> <p>This command inserts the text of another document or file into the parsed file. Any included file is subject to the usual access control. If the directory containing the parsed file has <a href="core.html#options">Options</a> <code>IncludesNOEXEC</code> set, then only documents with a text MIME type (<code>text/plain</code>, <code>text/html</code> etc.) will be included. Otherwise CGI scripts are invoked as normal using the complete URL given in the command, including any query string.</p> <p>An attribute defines the location of the document; the inclusion is done for each attribute given to the include command. The valid attributes are:</p> <dl> <dt><code>file</code></dt> <dd>The value is a path relative to the directory containing the current document being parsed. It cannot contain <code>../</code>, nor can it be an absolute path. Therefore, you cannot include files that are outside of the document root, or above the current document in the directory structure. The <code>virtual</code> attribute should always be used in preference to this one.</dd> <dt><code><a id="includevirtual" name="includevirtual">virtual</a></code></dt> <dd><p>The value is a (%-encoded) URL-path. The URL cannot contain a scheme or hostname, only a path and an optional query string. If it does not begin with a slash (/) then it is taken to be relative to the current document.</p> <p>A URL is constructed from the attribute, and the output the server would return if the URL were accessed by the client is included in the parsed output. Thus included files can be nested.</p> <p>If the specified URL is a CGI program, the program will be executed and its output inserted in place of the directive in the parsed file. You may include a query string in a CGI url:</p> <div class="example"><p><code> <!--#include virtual="/cgi-bin/example.cgi?argument=value" --> </code></p></div> <p><code>include virtual</code> should be used in preference to <code>exec cgi</code> to include the output of CGI programs into an HTML document.</p> </dd> </dl> <h3><a name="element.printenv" id="element.printenv">The printenv Element</a></h3> <p>This prints out a listing of all existing variables and their values. Special characters are entity encoded (see the <code><a href="#element.echo">echo</a></code> element for details) before being output. There are no attributes.</p> <div class="example"><h3>Example</h3><p><code> <!--#printenv --> </code></p></div> <h3><a name="element.set" id="element.set">The set Element</a></h3> <p>This sets the value of a variable. Attributes:</p> <dl> <dt><code>var</code></dt> <dd>The name of the variable to set.</dd> <dt><code>value</code></dt> <dd>The value to give a variable.</dd> </dl> <div class="example"><h3>Example</h3><p><code> <!--#set var="category" value="help" --> </code></p></div> </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="includevars" id="includevars">Include Variables</a></h2> <p>In addition to the variables in the standard CGI environment, these are available for the <code>echo</code> command, for <code>if</code> and <code>elif</code>, and to any program invoked by the document.</p> <dl> <dt><code>DATE_GMT</code></dt> <dd>The current date in Greenwich Mean Time.</dd> <dt><code>DATE_LOCAL</code></dt> <dd>The current date in the local time zone.</dd> <dt><code>DOCUMENT_NAME</code></dt> <dd>The filename (excluding directories) of the document requested by the user.</dd> <dt><code>DOCUMENT_URI</code></dt> <dd>The (%-decoded) URL path of the document requested by the user. Note that in the case of nested include files, this is <em>not</em> the URL for the current document.</dd> <dt><code>LAST_MODIFIED</code></dt> <dd>The last modification date of the document requested by the user.</dd> <dt><code>QUERY_STRING_UNESCAPED</code></dt> <dd>If a query string is present, this variable contains the (%-decoded) query string, which is <em>escaped</em> for shell usage (special characters like <code>&</code> etc. are preceded by backslashes).</dd> </dl></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="substitution" id="substitution">Variable Substitution</a></h2> <p>Variable substitution is done within quoted strings in most cases where they may reasonably occur as an argument to an SSI directive. This includes the <code>config</code>, <code>exec</code>, <code>flastmod</code>, <code>fsize</code>, <code>include</code>, <code>echo</code>, and <code>set</code> directives, as well as the arguments to conditional operators. You can insert a literal dollar sign into the string using backslash quoting:</p> <div class="example"><p><code> <!--#if expr="$a = \$test" --> </code></p></div> <p>If a variable reference needs to be substituted in the middle of a character sequence that might otherwise be considered a valid identifier in its own right, it can be disambiguated by enclosing the reference in braces, <em>a la</em> shell substitution:</p> <div class="example"><p><code> <!--#set var="Zed" value="${REMOTE_HOST}_${REQUEST_METHOD}" --> </code></p></div> <p>This will result in the <code>Zed</code> variable being set to "<code>X_Y</code>" if <code>REMOTE_HOST</code> is "<code>X</code>" and <code>REQUEST_METHOD</code> is "<code>Y</code>".</p> <p>The below example will print "in foo" if the <code>DOCUMENT_URI</code> is <code>/foo/file.html</code>, "in bar" if it is <code>/bar/file.html</code> and "in neither" otherwise:</p> <div class="example"><p><code> <!--#if expr='"$DOCUMENT_URI" = "/foo/file.html"' --><br /> <span class="indent"> in foo<br /> </span> <!--#elif expr='"$DOCUMENT_URI" = "/bar/file.html"' --><br /> <span class="indent"> in bar<br /> </span> <!--#else --><br /> <span class="indent"> in neither<br /> </span> <!--#endif --> </code></p></div></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="flowctrl" id="flowctrl">Flow Control Elements</a></h2> <p>The basic flow control elements are:</p> <div class="example"><p><code> <!--#if expr="<var>test_condition</var>" --><br /> <!--#elif expr="<var>test_condition</var>" --><br /> <!--#else --><br /> <!--#endif --> </code></p></div> <p>The <code>if</code> element works like an if statement in a programming language. The test condition is evaluated and if the result is true, then the text until the next <code>elif</code>, <code>else</code> or <code>endif</code> element is included in the output stream.</p> <p>The <code>elif</code> or <code>else</code> statements are be used to put text into the output stream if the original <var>test_condition</var> was false. These elements are optional.</p> <p>The <code>endif</code> element ends the <code>if</code> element and is required.</p> <p><var>test_condition</var> is one of the following:</p> <dl> <dt><code><var>string</var></code></dt> <dd>true if <var>string</var> is not empty</dd> <dt><code><var>string1</var> = <var>string2</var><br /> <var>string1</var> != <var>string2</var></code></dt> <dd><p>Compare <var>string1</var> with <var>string2</var>. If <var>string2</var> has the form <code>/<var>string2</var>/</code> then it is treated as a regular expression. Regular expressions are
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -