{"id":9026,"date":"2015-04-27T08:12:06","date_gmt":"2015-04-27T00:12:06","guid":{"rendered":"http:\/\/bohu.net\/blog\/?p=9026"},"modified":"2015-04-27T08:12:06","modified_gmt":"2015-04-27T00:12:06","slug":"shtml%e4%b8%ad%e7%9a%84%e8%84%9a%e6%9c%ac-ssi-%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%ab%af%e5%8c%85%e5%90%ab-server-side-includes","status":"publish","type":"post","link":"https:\/\/www.bohu.net\/blog\/9026\/","title":{"rendered":"shtml\u4e2d\u7684\u811a\u672c &#8211; SSI \u670d\u52a1\u5668\u7aef\u5305\u542b (Server Side Includes)"},"content":{"rendered":"<h1 class=\"guide\">\u670d\u52a1\u5668\u7aef\u5305\u542b<\/h1>\n<p>&nbsp;<\/p>\n<h2 class=\"guide\"><a name=\"_intro\"><\/a>\u4ecb\u7ecd<\/h2>\n<div id=\"page-content\">\n<div class=\"section\">\n<p>\u670d\u52a1\u5668\u7aef\u5305\u542b(Server Side Includes)\uff0c\u901a\u5e38\u7b80\u79f0\u4e3aSSI\uff0c\u662fHTML\u9875\u9762\u4e2d\u7684\u6307\u4ee4\uff0c\u5728\u9875\u9762\u88ab\u63d0\u4f9b\u65f6\u7531\u670d\u52a1\u5668\u8fdb\u884c\u8fd0\u7b97\uff0c\u4ee5\u5bf9\u73b0\u6709HTML\u9875\u9762\u589e\u52a0\u52a8\u6001\u751f\u6210\u7684\u5185\u5bb9\uff0c\u800c\u65e0\u987b\u901a\u8fc7CGI\u7a0b\u5e8f\u63d0\u4f9b\u5176\u6574\u4e2a\u9875\u9762\uff0c\u6216\u8005\u4f7f\u7528\u5176\u4ed6\u52a8\u6001\u6280\u672f\u3002<\/p>\n<div id=\"page-content\">\n<div class=\"section\">\n<p>\u5bf9\u4ec0\u4e48\u65f6\u5019\u7528SSI\uff0c\u800c\u4ec0\u4e48\u65f6\u5019\u7528\u67d0\u4e9b\u7a0b\u5e8f\u751f\u6210\u6574\u4e2a\u9875\u9762\u7684\u6743\u8861\uff0c\u53d6\u51b3\u4e8e\u9875\u9762\u4e2d\u6709\u591a\u5c11\u5185\u5bb9\u662f\u9759\u6001\uff0c\u6709\u591a\u5c11\u5185\u5bb9\u9700\u8981\u5728\u6bcf\u6b21\u9875\u9762\u88ab\u63d0\u4f9b\u65f6\u91cd\u65b0\u8ba1\u7b97\u3002SSI\u662f\u4e00\u79cd\u589e\u52a0\u5c0f\u6bb5\u4fe1\u606f\u7684\u597d\u65b9\u6cd5\uff0c\u8bf8\u5982\u5f53\u524d\u65f6\u95f4\u3002\u5982\u679c\u4f60\u7684\u9875\u9762\u5927\u90e8\u5206\u662f\u5728\u88ab\u63d0\u4f9b\u65f6\u751f\u6210\u7684\uff0c\u90a3\u5c31\u8981\u53e6\u627e\u65b9\u6848\u4e86\u3002<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>\u3002\u5c06\u670d\u52a1\u5668\u4fe1\u606f\u6dfb\u52a0\u5230\u4e00\u4e2a HTML \u6587\u6863\u3002\u5305\u62ec\u4ee5\u4e0b\u7684\u5f62\u5f0f\uff1a<\/p>\n<pre class=\"brush:html\">&lt;!--#command variablename=\"value\"--&gt;<\/pre>\n<table cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr valign=\"top\">\n<td class=\"main\" rowspan=\"2\">Whether or not you can use SSI on your site depends on your provider. Ask your favourite support person if you can use SSI, what server software is used and if there are any special techniques, conditions or rules. For example, on my site I can only use SSI in files that have an .shtml extension instead of the normal .html one. You also have to ask what path to files to use.<\/p>\n<p>Unfortunately, not all includes explained here work for all servers. For example, the #hide and #show includes are specific to WebStar. With Apache server software, you can achieve the same things by using #if and #endif.<\/p>\n<h2 class=\"guide\"><a name=\"_timefmt\"><\/a>\u66f4\u6539\u65f6\u95f4\u683c\u5f0f<\/h2>\n<p>Before starting to use server side includes, you need to configure a number of things. For starters, choose a format for date and time you like (the <a href=\"http:\/\/www.weijers.net\/guide\/ssi.php#echo\">#echo<\/a> command is explained later in this chapter).<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#config timefmt=&#8221;%A, %d %B %Y at %H:%M:%S&#8221;&#8211;&gt;<br \/>\n&lt;!&#8211;#echo var=&#8221;date_gmt&#8221;&#8211;&gt;<\/p>\n<p class=\"example\"><!--#config timefmt=\"%A, %d %B %Y at %H:%M:%S\"--> <!--#echo var=\"date_gmt\"--><\/p>\n<p>Below is a table of many of the options you can use. You can also include things like colons, commas and slashes as well as bits of text and HTML. You can mix the elements below at will.<\/p>\n<table border=\"0\" width=\"400\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><b>Element<\/b><\/td>\n<td><b>Value<\/b><\/td>\n<td><b>Example<\/b><\/td>\n<\/tr>\n<tr>\n<td>%a<\/td>\n<td>Abbreviated day of the week<\/td>\n<td>Sun<\/td>\n<\/tr>\n<tr>\n<td>%A<\/td>\n<td>Day of the week<\/td>\n<td>Sunday<\/td>\n<\/tr>\n<tr>\n<td>%b<\/td>\n<td>Abbreviated month name<\/td>\n<td>Jan<\/td>\n<\/tr>\n<tr>\n<td>%B<\/td>\n<td>Month in full<\/td>\n<td>January<\/td>\n<\/tr>\n<tr>\n<td>%d<\/td>\n<td>Date<\/td>\n<td>1 (and not 01)<\/td>\n<\/tr>\n<tr>\n<td>%H<\/td>\n<td>24-hour clock hour<\/td>\n<td>13<\/td>\n<\/tr>\n<tr>\n<td>%I<\/td>\n<td>12-hour clock hour<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>%j<\/td>\n<td>Decimal day of the year<\/td>\n<td>360<\/td>\n<\/tr>\n<tr>\n<td>%m<\/td>\n<td>Month number<\/td>\n<td>11<\/td>\n<\/tr>\n<tr>\n<td>%M<\/td>\n<td>Minutes<\/td>\n<td>08<\/td>\n<\/tr>\n<tr>\n<td>%p<\/td>\n<td>AM or PM<\/td>\n<td>AM<\/td>\n<\/tr>\n<tr>\n<td>%S<\/td>\n<td>Seconds<\/td>\n<td>09<\/td>\n<\/tr>\n<tr>\n<td>%U<\/td>\n<td>Week of the year (also %W)<\/td>\n<td>49<\/td>\n<\/tr>\n<tr>\n<td>%w<\/td>\n<td>Day of the week number<\/td>\n<td>05<\/td>\n<\/tr>\n<tr>\n<td>%y<\/td>\n<td>Year of the century<\/td>\n<td>95<\/td>\n<\/tr>\n<tr>\n<td>%Y<\/td>\n<td>Year<\/td>\n<td>1995<\/td>\n<\/tr>\n<tr>\n<td>%Z<\/td>\n<td>Time zone<\/td>\n<td>EST<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Here are some more examples of different formats:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#config timefmt=&#8221;Week %U of %y&#8221;&#8211;&gt;<br \/>\n&lt;!&#8211;#echo var=&#8221;date_gmt&#8221;&#8211;&gt;<\/p>\n<p class=\"example\"><!--#config timefmt=\"Week %U of %y\"--> <!--#echo var=\"date_gmt\"--><\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#config timefmt=&#8221;%d\/%m\/%y, day %j of the year&#8221;&#8211;&gt;<br \/>\n&lt;!&#8211;#echo var=&#8221;date_gmt&#8221;&#8211;&gt;<\/p>\n<p class=\"example\"><!--#config timefmt=\"%d\/%m\/%y, day %j of the year\"--> <!--#echo var=\"date_gmt\"--><\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#config timefmt=&#8221;%I:%S %p&#8221;&#8211;&gt;<br \/>\n&lt;!&#8211;#echo var=&#8221;date_gmt&#8221;&#8211;&gt;<\/p>\n<p class=\"example\"><!--#config timefmt=\"%I:%S %p\"--> <!--#echo var=\"date_gmt\"--><\/p>\n<p>The last format you have set will remain valid throughout the rest of the page. However, unless you want to use the default format (which usually is something like 98\/07\/12:16:45:34) you will have to set your favourite time format in every page that uses server side includes that have to do with time.<\/p>\n<h2 class=\"guide\"><a name=\"_sizefmt\"><\/a>\u66f4\u6539\u5927\u5c0f\u683c\u5f0f<\/h2>\n<p>You can also specify the way file sizes are displayed.<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#config sizefmt=&#8221;bytes&#8221;&#8211;&gt;<br \/>\n&lt;!&#8211;#fsize file=&#8221;top.gif&#8221;&#8211;&gt;<br \/>\n&lt;!&#8211;#config sizefmt=&#8221;abbrev&#8221;&#8211;&gt;<br \/>\n&lt;!&#8211;#fsize file=&#8221;top.gif&#8221;&#8211;&gt;<\/p>\n<p class=\"example\"><!--#config sizefmt=\"bytes\"--> <!--#fsize file=\"top.gif\"--><br \/>\n<!--#config sizefmt=\"abbrev\"--> <!--#fsize file=\"top.gif\"--><\/p>\n<p>The #fsize include is explained later in this chapter. You can see that the &#8220;bytes&#8221; option gives the size in full in bytes, the &#8220;abbrev&#8221; option gives the size in kilobytes.<\/p>\n<h2 class=\"guide\"><a name=\"_errmsg\"><\/a>\u81ea\u5b9a\u4e49\u9519\u8bef\u6d88\u606f<\/h2>\n<p>You can change the default error message to anything you want. Here is an example of changing the error message and then trying to include the non-existent file &#8220;nosuchfile.html&#8221;:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#config errmsg=&#8221;Sorry, an error occurred. Please mail your complaints to webmaster@somewhere.net&#8221;&#8211;&gt;<\/p>\n<p>&lt;!&#8211;#include file=&#8221;nosuchfile.html&#8221;&#8211;&gt;<\/p>\n<p><!--#config errmsg=\"Sorry, an error occurred. Please mail your complaints to webmaster@somewhere.net\"--><\/p>\n<p class=\"example\"><!--#include file=\"nosuchfile.html\"--><\/p>\n<p>There is only one error message available. However, you can change the error message more than once in a single html file:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#config errmsg=&#8221;Sorry, an error occurred including nosuchfile.html. Please mail your complaints to webmaster@somewhere.net&#8221;&#8211;&gt;<\/p>\n<p>&lt;!&#8211;#include file=&#8221;nosuchfile.html&#8221;&#8211;&gt;<\/p>\n<p>&lt;!&#8211;#config errmsg=&#8221;Sorry, an error occurred including nosuchfileagain.html. Please mail your complaints to webmaster@somewhere.net&#8221;&#8211;&gt;<\/p>\n<p>&lt;!&#8211;#include file=&#8221;nosuchfileagain.html&#8221;&#8211;&gt;<\/p>\n<p><!--#config errmsg=\"Sorry, an error occurred including nosuchfile.html. Please mail your complaints to webmaster@somewhere.net\"--><\/p>\n<p class=\"example\"><!--#include file=\"nosuchfile.html\"--><\/p>\n<p><!--#config errmsg=\"Sorry, an error occurred including nosuchfileagain.html. Please mail your complaints to webmaster@somewhere.net\"--><\/p>\n<p class=\"example\"><!--#include file=\"nosuchfileagain.html\"--><\/p>\n<p>Specifying your own error messages will make it easier for you to spot and solve problems. If you want to use more than one error message, you have to make sure that you change the error message before the command it refers to.<\/p>\n<h2 class=\"guide\"><a name=\"_files\"><\/a>\u5305\u62ec\u6587\u4ef6<\/h2>\n<p>The include command allows you to dynamically insert other HTML files into the current HTML file. Use it like this:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#include file=&#8221;file.shtml&#8221;&#8211;&gt;<\/p>\n<p>What path to use, again, depends on your provider. Normally it will be a path that is local to the server, so it will not include http:\/\/etc. The most sensible use of this command is to take standard bits of your pages such as headers and footer and put them in a separate file. On all of your pages you use the include command to include that file. That way, in order to change the footer on all pages, you only need to change one file. For example, you could make a simple text file that contains:<\/p>\n<p class=\"sourcecode\">&lt;P ALIGN=&#8221;center&#8221;&gt;Copyright 1998 Tom, Dick and Harry&lt;BR&gt;<br \/>\nPlease mail us at tom.dick@harry.com&lt;\/P<\/p>\n<p>You save this file as ssifooter.html and include it in your other files by using:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#include file=&#8221;ssifooter.html&#8221;&#8211;&gt;<\/p>\n<p class=\"example\"><!--#include file=\"ssifooter.html\"--><\/p>\n<p>The files you include can be plain text files or can include HTML. You don&#8217;t need to give them &lt;HEAD&gt; and &lt;BODY&gt; tags, just put in whatever you want to insert. In these files you can use whatever HTML you want and you can make links, etc.<\/p>\n<h2 class=\"guide\"><a name=\"_hide\"><\/a>\u9690\u85cf \/ \u663e\u793a<\/h2>\n<p>With the Hide and Show commands you can avoid that your reader sees certain parts of the document:<\/p>\n<p class=\"sourcecode\">&lt;P&gt;Now you see me, &lt;!&#8211;#hide&#8211;&gt; This text is not shown. &lt;!&#8211;#show&#8211;&gt; now you don&#8217;t.&lt;\/P<\/p>\n<p>Show and Hide can be used to temporary exclude parts of your document. Hide and Show only work under WebStar, so I cannot show you an example here.<\/p>\n<h2 class=\"guide\"><a name=\"_hidetime\"><\/a>\u6839\u636e\u65f6\u95f4\u9690\u85cf\u548c\u663e\u793a<\/h2>\n<p>The next example shows how to display bits of HTML only after certain days. Comparisons like this always use the default time format of 1998\/07\/24:17:34:45 no matter what you have done with the <a href=\"http:\/\/www.weijers.net\/guide\/ssi.php#timefmt\">timefmt<\/a> option.<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show after=&#8221;1998\/06\/30&#8243;&#8211;&gt;<br \/>\nThis text is shown after 30 June 1998.<br \/>\n&lt;!&#8211;#show&#8211;&gt;<\/p>\n<p>&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show after=&#8221;1999\/06\/30&#8243;&#8211;&gt;<br \/>\nThis text is shown after 30 June 1999.<br \/>\n&lt;!&#8211;#show&#8211;&gt;<\/p>\n<p>Or you can show and hide things on specific days using a combination of &#8216;hide after&#8217; and &#8216;show after&#8217;:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show during=&#8221;1998\/07\/12&#8243;&#8211;&gt;<br \/>\nThis text is shown on 12 July 1998.<br \/>\n&lt;!&#8211;#show&#8211;&gt;<\/p>\n<p>&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show during=&#8221;1998\/07\/13&#8243;&#8211;&gt;<br \/>\nThis text is shown on 13 July 1998.<br \/>\n&lt;!&#8211;#show&#8211;&gt;<\/p>\n<p>&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show during=&#8221;1998\/07\/14&#8243;&#8211;&gt;<br \/>\nThis text is shown on 14 July 1998.<br \/>\n&lt;!&#8211;#show&#8211;&gt;<\/p>\n<p>As you can see, you do not have to specify a full date and time but only what is relevant for you. If you would want to show something during 1998 you could use: during=&#8221;1998&#8243;.<\/p>\n<h2 class=\"guide\"><a name=\"_hidebrowser\"><\/a>\u4f9d\u636e\u65f6\u95f4\u9690\u85cf\u548c\u663e\u793a<\/h2>\n<p>Here is an example of how to show a bit of text only to a user of Netscape&#8217;s Navigator:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show var=&#8221;http_user_agent&#8221; operator=&#8221;contains&#8221;<br \/>\nvalue=&#8221;nav&#8221;&#8211;&gt;<br \/>\nWelcome Netscape Navigator user!<br \/>\n&lt;!&#8211;#show&#8211;&gt;<\/p>\n<p>&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show var=&#8221;http_user_agent&#8221; operator=&#8221;contains&#8221;<br \/>\nvalue=&#8221;MSIE&#8221;&#8211;&gt;<br \/>\nWelcome Internet Explorer user!<br \/>\n&lt;!&#8211;#show&#8211;&gt;<\/p>\n<p>As you can see in this example, the output of Webstar is by default on. That&#8217;s why you start any of these examples by switching the output of (#hide) and then switching it on again if the appropriate condition is fulfilled. At the end of the example you switch the output on again with a #show include. Again, show and hide do not work under Apache so I cannot show you the result here.<\/p>\n<h2 class=\"guide\"><a name=\"_hiderandom\"><\/a>\u968f\u673a\u9690\u85cf\u548c\u663e\u793a<\/h2>\n<p>Show and Hide can also be used at random:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show var=&#8221;random&#8221; op=&#8221;&lt;&#8221; value=&#8221;50&#8243; &#8211;&gt;<br \/>\nHeads<br \/>\n&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show var=&#8221;random&#8221; op=&#8221;=&gt;&#8221; value=&#8221;50&#8243; &#8211;&gt;<br \/>\nTails<br \/>\n&lt;!&#8211;#show&#8211;&gt;<\/p>\n<p>If you do a couple of reloads, you should see the text change. Of course you can use the same thing to show and hide images or any other HTML. The number that is used by Webstar is a random number ranging from 1 to 99 inclusive. Here is an example for three random texts:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show var=&#8221;random&#8221; op=&#8221;&lt;&#8221; value=&#8221;33&#8243; &#8211;&gt;<br \/>\nTo be or not to be,<br \/>\n&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show var=&#8221;random&#8221; op=&#8221;=&gt;&#8221; value=&#8221;34&#8243; &#8211;&gt;<br \/>\n&lt;!&#8211;#hide var=&#8221;random&#8221; op=&#8221;&gt;&#8221; value=&#8221;66&#8243; &#8211;&gt;<br \/>\nthat&#8217;s the question,<br \/>\n&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show var=&#8221;random&#8221; op=&#8221;&gt;&#8221; value=&#8221;66&#8243; &#8211;&gt;<br \/>\nmy dear Watson.<br \/>\n&lt;!&#8211;#show&#8211;&gt;<\/p>\n<h2 class=\"guide\"><a name=\"_hidemore\"><\/a>\u66f4\u591a\u7684\u9690\u85cf\u548c\u663e\u793a<\/h2>\n<p>In fact you can show and hide text at will using any of the environment variables (see the section on <a href=\"http:\/\/www.weijers.net\/guide\/ssi.php#echo\">Echo<\/a> below). This example shows a bit of text to a user with IP address 195.99.40.125:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#hide&#8211;&gt;<br \/>\n&lt;!&#8211;#show var=&#8221;remote_addr&#8221; operator=&#8221;=&#8221; value=&#8221;195.99.40.125&#8243;&#8211;&gt;<br \/>\nWelcome BTinternet user!<br \/>\n&lt;!&#8211;#show&#8211;&gt;<\/p>\n<p>If you have friends with fixed IP addresses you can leave messages especially for them in the same manner. Finally, you should know which operators are available:<\/p>\n<table border=\"0\" width=\"80%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><b>Operator<\/b><\/td>\n<td><b>Meaning<\/b><\/td>\n<\/tr>\n<tr>\n<td>&#8220;contains&#8221; or &#8220;con&#8221;<\/td>\n<td>variable contains the value string<\/td>\n<\/tr>\n<tr>\n<td>&#8220;starts with&#8221; or &#8220;start&#8221;<\/td>\n<td>variable starts with the value string<\/td>\n<\/tr>\n<tr>\n<td>&#8220;ends with&#8221; or &#8220;end&#8221;<\/td>\n<td>variable ends with the value string<\/td>\n<\/tr>\n<tr>\n<td>&#8220;=&#8221; or &#8220;==&#8221;<\/td>\n<td>variable equals the value string<\/td>\n<\/tr>\n<tr>\n<td>&#8220;!=&#8221; or &#8220;&lt;&gt;&#8221;<\/td>\n<td>variable does not equal the value string<\/td>\n<\/tr>\n<tr>\n<td>&#8220;&lt;&#8220;<\/td>\n<td>variable is less than the value string<\/td>\n<\/tr>\n<tr>\n<td>&#8220;&lt;=&#8221; or &#8220;=&lt;&#8220;<\/td>\n<td>variable is less than or equal to the value string<\/td>\n<\/tr>\n<tr>\n<td>&#8220;&gt;&#8221;<\/td>\n<td>variable is greater than the value string<\/td>\n<\/tr>\n<tr>\n<td>&#8220;&gt;=&#8221; or &#8220;=&gt;&#8221;<\/td>\n<td>variable is greater than or equal to the value string<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 class=\"guide\"><a name=\"_ifendif\"><\/a>If \u548c Endif<\/h2>\n<p>Because this server runs Apache I could not show the examples of #hide and #show. I can, however, demonstrate the #if and #endif includes (if and endif, in turn, do not work under Webstar):<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#config timefmt=&#8221;%A&#8221;&#8211;&gt;<br \/>\n&lt;!&#8211;#if expr=&#8221;$date_gmt = Friday&#8221; &#8211;&gt;<br \/>\nHang in there, it&#8217;s almost weekend<br \/>\n&lt;!&#8211;#elif expr=&#8221;($date_gmt = Saturday) || ($date_gmt = Sunday)&#8221; &#8211;&gt;<br \/>\nHave a nice weekend<br \/>\n&lt;!&#8211;#else &#8211;&gt;<br \/>\nHave a good day<br \/>\n&lt;!&#8211;#endif &#8211;&gt;<\/p>\n<p class=\"example\"><!--#config timefmt=\"%A\"--> <!--#if expr=\"$date_gmt = Friday\" --> Hang in there, it&#8217;s almost weekend <!--#elif expr=\"($date_gmt = Saturday) || ($date_gmt = Sunday)\" --> Have a nice weekend <!--#else --> Have a good day <!--#endif --><\/p>\n<p>The first thing you will notice is that the #if include, opposite to the #hide and #show, does use the date as formatted with timefmt. This has some clear advantages. You can also see that this example is a bit easier to understand the #show and #hide spaghetti that WebStar seems to need. Note that the #if and #endif are obligatory, the #elif and #else are optional. This example uses date_gmt which is London time -ignoring summertime- rather than date_local which depends on where the server is.<\/p>\n<p>The following operators are available:<\/p>\n<table border=\"0\" width=\"80%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><b>Operator<\/b><\/td>\n<td><b>Meaning<\/b><\/td>\n<\/tr>\n<tr>\n<td>string1 = string2<\/td>\n<td>string1 equals string2<\/td>\n<\/tr>\n<tr>\n<td>string1 != string2<\/td>\n<td>string1 does not equal string2<\/td>\n<\/tr>\n<tr>\n<td>string1 &lt; string2<\/td>\n<td>string1 is less than string2<\/td>\n<\/tr>\n<tr>\n<td>string1 &lt;= string2<\/td>\n<td>string1 is less than or equal to string2<\/td>\n<\/tr>\n<tr>\n<td>string1 &gt; string2<\/td>\n<td>string1 is greater than string2<\/td>\n<\/tr>\n<tr>\n<td>string1 &gt;= string2<\/td>\n<td>string1 is greater than or equal to string2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 class=\"guide\"><a name=\"_ifbrowser\"><\/a>If, Endif\u00a0\u548c\u73af\u5883\u53d8\u91cf<\/h2>\n<p>you can use the #if include to show different information to different browsers. Each browser sets the environment variable http_user_agent differently. This is how Netscape Navigator 4.04, Microsoft Internet Exploder and Apple&#8217;s Cyberdog respectively do it:<\/p>\n<p class=\"example\">Mozilla\/4.04 (Macintosh; I; PPC, Nav)<br \/>\nMozilla\/4.0 (compatible; MSIE 4.0; Mac_PowerPC)<br \/>\nCyberdog\/2.0 (Macintosh; PPC)<\/p>\n<p>As you can see these are all the Macintosh versions. By the way, this is what your own browser makes of http_user_agent: <!--#echo var=\"http_user_agent\"-->. So this is how to show different information to different browsers:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#if expr=&#8221;$HTTP_USER_AGENT=\/MSIE\/ &#8221; &#8211;&gt;<br \/>\nFight the Microsoft Monopoly. Get Netscape!<br \/>\n&lt;!&#8211;#elif expr=&#8221;$HTTP_USER_AGENT=\/Nav\/ &#8221; &#8211;&gt;<br \/>\nWelcome Netscape Navigator user!<br \/>\n&lt;!&#8211;#elif expr=&#8221;$HTTP_USER_AGENT=\/Cyberdog\/ &#8221; &#8211;&gt;<br \/>\nWelcome Apple Cyberdog user!<br \/>\n&lt;!&#8211;#else &#8211;&gt;<br \/>\nWelcome! So what browser are you using?<br \/>\n&lt;!&#8211;#endif &#8211;&gt;<\/p>\n<p class=\"example\"><!--#if expr=\"$HTTP_USER_AGENT=\/MSIE\/ \" --> Fight the Microsoft Monopoly. Get Netscape! <!--#elif expr=\"$HTTP_USER_AGENT=\/Nav\/ \" --> Welcome Netscape Navigator user! <!--#elif expr=\"$HTTP_USER_AGENT=\/Cyberdog\/ \" --> Welcome Apple Cyberdog user! <!--#else --> Welcome! So what browser are you using? <!--#endif --><\/p>\n<p>Note that the \/Nav\/ I am looking for here is produced by Netscape Navigator, which is Communicator without the news, mail and webeditor modules. The above is obviously not an exhaustive list of browsers, which is why there is also an #else include for all the browsers that are not covered.<\/p>\n<p>The two slashes around MSIE, Nav and Cyberdog in the example above means that the second string is interpreted as a regular expression, commonly used under Unix. In this case it checks if http_user_agent contains that string.<\/p>\n<h2 class=\"guide\"><a name=\"_set\"><\/a>Set<\/h2>\n<p>The #set include can be used to create your own variables and assign them a value. Variables can be printed or can be used in #if statements:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#set var=&#8221;carmodel&#8221; value=&#8221;Mercedes&#8221; &#8211;&gt;<br \/>\n&lt;!&#8211;#echo var=&#8221;carmodel&#8221; &#8211;&gt;&lt;BR&gt;<br \/>\n&lt;!&#8211;#if expr=&#8221;$carmodel = Mercedes&#8221; &#8211;&gt;<br \/>\nThat&#8217;s a jolly nice car<br \/>\n&lt;!&#8211;#endif &#8211;&gt;<\/p>\n<p class=\"example\"><!--#set var=\"carmodel\" value=\"Mercedes\" --> <!--#echo var=\"carmodel\" --><br \/>\n<!--#if expr=\"$carmodel = Mercedes\" --> That&#8217;s a jolly nice car <!--#endif --><\/p>\n<p>The $ sign in the #if include is needed to ensure that &#8220;carmodel&#8221; is interpreted as a variable, not as a string.<\/p>\n<h2 class=\"guide\"><a name=\"_echo\"><\/a>Echo<\/h2>\n<p>ECHO can be used to insert information from the browser and the server into your document, the so-called environment variables. The following possibilities are available:<\/p>\n<p class=\"sourcecode\">Document Name: &lt;!&#8211;#echo var=&#8221;document_name&#8221;&#8211;&gt;<br \/>\nDocument URI: &lt;!&#8211;#echo var=&#8221;document_uri&#8221;&#8211;&gt;<br \/>\nLocal Date: &lt;!&#8211;#echo var=&#8221;date_local&#8221;&#8211;&gt;<br \/>\nGMT Date: &lt;!&#8211;#echo var=&#8221;date_gmt&#8221;&#8211;&gt;<br \/>\nLast Modified: &lt;!&#8211;#echo var=&#8221;last_modified&#8221;&#8211;&gt;<br \/>\nServer Software: &lt;!&#8211;#echo var=&#8221;server_software&#8221;&#8211;&gt;<br \/>\nServer Name: &lt;!&#8211;#echo var=&#8221;server_name&#8221;&#8211;&gt;<br \/>\nServer Protocol: &lt;!&#8211;#echo var=&#8221;server_protocol&#8221;&#8211;&gt;<br \/>\nServer Port: &lt;!&#8211;#echo var=&#8221;server_port&#8221;&#8211;&gt;<br \/>\nGateway Interface: &lt;!&#8211;#echo var=&#8221;gateway_interface&#8221;&#8211;&gt;<br \/>\nRequest Method: &lt;!&#8211;#echo var=&#8221;request_method&#8221;&#8211;&gt;<br \/>\nScript Name: &lt;!&#8211;#echo var=&#8221;script_name&#8221;&#8211;&gt;<br \/>\nRemote Host: &lt;!&#8211;#echo var=&#8221;remote_host&#8221;&#8211;&gt;<br \/>\nRemote Address: &lt;!&#8211;#echo var=&#8221;remote_addr&#8221;&#8211;&gt;<br \/>\nRemote User: &lt;!&#8211;#echo var=&#8221;remote_user&#8221;&#8211;&gt;<br \/>\nContent Type: &lt;!&#8211;#echo var=&#8221;content_type&#8221;&#8211;&gt;<br \/>\nContent Length: &lt;!&#8211;#echo var=&#8221;content_length&#8221;&#8211;&gt;<br \/>\nHTTP Accept: &lt;!&#8211;#echo var=&#8221;http_accept&#8221;&#8211;&gt;<br \/>\nHTTP User Agent (Browser): &lt;!&#8211;#echo var=&#8221;http_user_agent&#8221;&#8211;&gt;<br \/>\nHTTP Cookie: &lt;!&#8211;#echo var=&#8221;http_cookie&#8221;&#8211;&gt;<br \/>\nUnescaped query string: &lt;!&#8211;#echo var=&#8221;query_string_unescaped&#8221;&#8211;&gt;<br \/>\nQuery String: &lt;!&#8211;#echo var=&#8221;query_string&#8221;&#8211;&gt;<br \/>\nPath Info: &lt;!&#8211;#echo var=&#8221;path_info&#8221;&#8211;&gt;<br \/>\nPath Translated: &lt;!&#8211;#echo var=&#8221;path_translated&#8221;&#8211;&gt;<br \/>\nReferer: &lt;!&#8211;#echo var=&#8221;referer&#8221;&#8211;&gt;<br \/>\nForwarded: &lt;!&#8211;#echo var=&#8221;forwarded&#8221;&#8211;&gt;<\/p>\n<p><!--#config errmsg=\"\"--> <!--#config timefmt=\"%A, %d %B %Y at %H:%M\"--><\/p>\n<p class=\"example\"><b>Document Name:<\/b> <!--#echo var=\"document_name\"--><br \/>\n<b>Document URI:<\/b> <!--#echo var=\"document_uri\"--><br \/>\n<b>Local Date:<\/b> <!--#echo var=\"date_local\"--><br \/>\n<b>GMT Date:<\/b> <!--#echo var=\"date_gmt\"--><br \/>\n<b>Last Modified:<\/b> <!--#echo var=\"last_modified\"--><br \/>\n<b>Server Software:<\/b> <!--#echo var=\"server_software\"--><br \/>\n<b>Server Name:<\/b> <!--#echo var=\"server_name\"--><br \/>\n<b>Server Protocol:<\/b> <!--#echo var=\"server_protocol\"--><br \/>\n<b>Server Port:<\/b> <!--#echo var=\"server_port\"--><br \/>\n<b>Gateway Interface:<\/b> <!--#echo var=\"gateway_interface\"--><br \/>\n<b>Request Method:<\/b> <!--#echo var=\"request_method\"--><br \/>\n<b>Script Name:<\/b> <!--#echo var=\"script_name\"--><br \/>\n<b>Remote Host:<\/b> <!--#echo var=\"remote_host\"--><br \/>\n<b>Remote Address:<\/b> <!--#echo var=\"remote_addr\"--><br \/>\n<b>Remote User:<\/b> <!--#echo var=\"remote_user\"--><br \/>\n<b>Content Type:<\/b> <!--#echo var=\"content_type\"--><br \/>\n<b>Content Length:<\/b> <!--#echo var=\"content_length\"--><br \/>\n<b>HTTP Accept:<\/b> <!--#echo var=\"http_accept\"--><br \/>\n<b>HTTP User Agent (Browser):<\/b> <!--#echo var=\"http_user_agent\"--><br \/>\n<b>HTTP Cookie:<\/b> <!--#echo var=\"http_cookie\"--><br \/>\n<b>Unescaped query string:<\/b> <!--#echo var=\"query_string_unescaped\"--><br \/>\n<b>Query String:<\/b> <!--#echo var=\"query_string\"--><br \/>\n<b>Path Info:<\/b> <!--#echo var=\"path_info\"--><br \/>\n<b>Path Translated:<\/b> <!--#echo var=\"path_translated\"--><br \/>\n<b>Referer:<\/b> <!--#echo var=\"referer\"--><br \/>\n<b>Forwarded:<\/b> <!--#echo var=\"forwarded\"--><\/p>\n<p>Not all ECHO commands always result in information being printed. This can depend on the server, on your browser and on the way you reached this page. The #echo include works both under WebStar and Apache.<\/p>\n<h2 class=\"guide\"><a name=\"_printenv\"><\/a>Print Environment<\/h2>\n<p>If you want to print the entire environment, you do not need to use a whole list of #echo includes. Instead you can use this shortcut.<\/p>\n<p><!--#config timefmt=\"%A, %d %B %Y at %H:%M\"--><\/p>\n<p class=\"sourcecode\">&lt;PRE&gt; &lt;!&#8211;#printenv &#8211;&gt; &lt;\/PRE&gt;<\/p>\n<div class=\"example\">\n<pre><!--#printenv -->\n\n<\/pre>\n<\/div>\n<p>Note that the environment includes the variable &#8220;carmodel&#8221; that was defined in an earlier example.<\/p>\n<h2 class=\"guide\"><a name=\"_exec\"><\/a>\u6267\u884c\u811a\u672c<\/h2>\n<p>You can use a server side include to run a script. This is what I use on my <a href=\"http:\/\/www.weijers.net\/index.shtml\">homepage<\/a>:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#exec cgi=&#8221;ssi.demo.cgi&#8221;&#8211;&gt;<\/p>\n<p class=\"example\"><!--#exec cgi=\"ssi.demo.cgi\"--><\/p>\n<p>The CGI script (which is in Perl 5) opens a file with a dozen quotes, selects one at random and prints it to the page. The script, by the way, is courtesy of <a href=\"http:\/\/www.worldwidemart.com\/scripts\/\">Matt Wright<\/a> who offers a brilliant collection of scripts.<\/p>\n<h2 class=\"guide\"><a name=\"_filesize\"><\/a>\u6587\u4ef6\u5927\u5c0f<\/h2>\n<p>You can insert the size of a file in this way:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#fsize file=&#8221;top.gif&#8221;&#8211;&gt;<\/p>\n<p class=\"example\"><!--#fsize file=\"top.gif\"--><\/p>\n<p>This inserts the size of the file top.gif (the logo at the top of this page). As explained earlier in this chapter, you can determine if the size is displayed in full bytes or abbreviated in kilobytes or megabytes.<\/p>\n<h2 class=\"guide\"><a name=\"_filedate\"><\/a>\u6587\u4ef6\u65e5\u671f<\/h2>\n<p>You can insert the date of a file in this way:<\/p>\n<p class=\"sourcecode\">&lt;!&#8211;#flastmod file=&#8221;top.gif&#8221;&#8211;&gt;<\/p>\n<p><!--#config timefmt=\"%A, %d %B %Y at %H:%M\"--><\/p>\n<p class=\"example\"><!--#flastmod file=\"top.gif\"--><\/p>\n<p>This inserts the date and the time the file top.gif (the logo at the top of this page) was last modified. The format of the date and time can be customized by you as explained earlier in this chapter.<\/p>\n<p><i>This page has been translated into <a href=\"http:\/\/www.webhostinghub.com\/support\/es\/misc\/weijers-ssi\">Spanish<\/a> language by Maria Ramos from <a href=\"http:\/\/www.webhostinghub.com\/\">Webhostinghub.com<\/a>.<\/i><\/p>\n<p>&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u670d\u52a1\u5668\u7aef\u5305\u542b &nbsp; \u4ecb\u7ecd \u670d\u52a1\u5668\u7aef\u5305\u542b(Server Side Includes)\uff0c\u901a\u5e38\u7b80\u79f0\u4e3aSSI\uff0c &hellip; <a href=\"https:\/\/www.bohu.net\/blog\/9026\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cshtml\u4e2d\u7684\u811a\u672c &#8211; SSI \u670d\u52a1\u5668\u7aef\u5305\u542b (Server Side Includes)\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":9027,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,11,23],"tags":[350,362,547,548],"class_list":["post-9026","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-html","category-web","category-23","tag-shtml","tag-ssi","tag-547","tag-548"],"_links":{"self":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/9026","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/comments?post=9026"}],"version-history":[{"count":0,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/9026\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/media?parent=9026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/categories?post=9026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/tags?post=9026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}