1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
<HTML><HEAD>
<TITLE>CGI Interface -- How Web Pages Run CGI Programs</TITLE>
<LINK rel=Previous href="cgi-ch2.htm">
<LINK rel=ToC href="toc.htm">
<LINK rel=Index href="master.htm">
<LINK rel=Next href="cgi-ch4.htm">
</HEAD><BODY BGCOLOR="#ffffff"><A NAME="topofpage"></A>
<TABLE WIDTH=100%>
<TR>
<TD ALIGN=LEFT>
<A NAME="topofpage"></A> <IMG SRC="as-c-sm.gif">
</TD>
<TD ALIGN=RIGHT>
<A href="cgi-ch2.htm"><IMG BORDER="0" src=navbprev.gif alt="[ Previous ]"></A>
<A href=toc.htm> <IMG BORDER="0" src=navbhome.gif alt="[ Contents ]"></A>
<A href=master.htm> <IMG BORDER="0" src=navbhelp.gif alt="[ Index ]"></A>
<A href="cgi-ch4.htm"> <IMG BORDER="0" src=navbnext.gif alt="[ Next ]"></A>
<A name="7983"> </A>
</TD>
</TR>
</TABLE>
<a name="8716">
</a><h3>How Web Pages Run CGI Programs</h3>
<p><a name="8734">
</a>There are several ways a Web page can run a CGI program:</p>
<ul><li><b>Direct Link:</b> A link in your page can reference a CGI program directly. Normally, such links are used when you do not need to send any variables to the program.<a name="11153">
</a>
<p><li><b><ISINDEX> Tag:</b> This tag can be included in the <HEAD> section of the page. For example, you could add this tag:<code></code><a name="11571">
</a>
<p><pre> <a name="11573"></a><ISINDEX HREF="/cgi-bin/search.pl" PROMPT="Search for:">
</pre><p><dl>
<dt>Normally, the <ISINDEX> tag is used to run search programs, but this is not a requirement. You can use this tag to run CGI programs if you don't care where the field is located in your page and your program accepts a single variable. <a name="11511">
</a>
<p><dt>When you use this tag, the browser adds a field to the Web page. Readers can type a string in this field. The server decodes the text the reader typed and sends it to your CGI program as separate command-line arguments. The advantage is you don't need to decode the input.<a name="11576">
</a>
<p></dl>
<li><b>Form:</b> You can create a form with multiple fields. Use forms to run CGI programs when your readers can choose or type values for one or more variables.The METHOD attribute of the <FORM> can be either "GET" or "POST".<a name="8764">
</a>
<p><ul>
<li>The "GET" method causes the field names and values to be passed to the program in the QUERY_STRING environment variable. <a name="11615">
</a>
<p><li>The "POST" method causes the field names and values to be passed to the program through standard input. If the input from your form may be long, it is best to use the POST method because long strings can be truncated when they are assigned to an environment variable.<a name="11620">
</a>
<p></ul>
</ul><a name="11484">
</a><h4>URLs that Run CGI Programs</h4>
<p><a name="11523">
</a>For each method of running a CGI program described in the previous section, the browser software sends a URL to the server. (In addition, the HTTP header sent with the URL includes some environment variables, which are described on <a href="cgi-ch4.htm#8698">page 108</a>.) </p>
<p><a name="11755">
</a>Generally the URL to run a CGI program can have these parts:</p>
<p><a name="11760">
</a><code>CGI path[/extra path information ][?query string]</code></p>
<ul><li>The <b>CGI path</b> is the location of the CGI program to run. The path can be a relative or absolute reference to the program file.<a name="11725">
</a>
<p><li>The optional <b>extra path information</b> can be included in the URL to provide either a directory location the CGI program should use or some extra information for the CGI program. The path is relative to the root directory for Web pages. The extra path information is available to the CGI program in the PATH_INFO environment variable.<a name="11765">
</a>
<p><li>The optional <b>query string</b> is preceded by a question mark (?) and contains either a single variable or a set of field names and variables for the CGI program to use. The query string is available to the CGI program in either the QUERY_STRING environment variable or the standard input location (if the form method is POST). <a name="11775">
</a>
<p><dl>
<dt>For example, the query string from a form with 3 fields could be:<a name="14650">
</a>
<p></dl>
</ul><p><a name="11818">
</a><code> Field1=Value1&Field2=Value2&Field3=Value3</code></p>
<dl>
<dt>Spaces in the query string are replaced with plus signs (+). Any special characters (such as ?, =, &, +) are replaced with %xx, where xx is the hexadecimal value for that character. (See <a href="cgi-ch4.htm#12719">page 111</a> for more on how the query string is encoded.)<a name="11819">
</a>
<p></dl>
<p><a name="11764">
</a>Here are some examples of URLs that could run a CGI program:</p>
<ul>
<li><code>http://www.mysite.com/cgi-bin/gettime</code><a name="11485">
</a>
<p><dl>
<dt>This URL runs the <code>gettime</code> program, which could return a page with the current time. There are no variables, so you might use this as a direct link.<a name="11486">
</a>
<p></dl>
<li><code>http://www.mysite.com/cgi-bin/listdir/misc/mydir</code><a name="11879">
</a>
<p><dl>
<dt>This URL runs the <code>listdir</code> program and passes it <code>/misc/mydir</code> as extra path information. This might be a direct link in a page.<a name="11880">
</a>
<p></dl>
<li><code>http://www.mysite.com/cgi-bin/search?navigate</code><a name="11487">
</a>
<p><dl>
<dt>This URL runs the <code>search</code> program and passes it the word "navigate" as input. This URL doesn't include any field names, so it might be passed by pages with an <ISINDEX> tag.<a name="11488">
</a>
<p></dl>
<li><code>http://www.webcrawler.com/cgi-bin/WebQuery?searchText=word</code><a name="11491">
</a>
<p><dl>
<dt>This is a real URL that runs the WebCrawler search program and passes a value for the searchText field of "word". Normally, CGI programs that accept field values like these are run from a form.<a name="11492">
</a>
<p></dl>
</ul>
<dl>
<dt>If your programs are not executed, make sure the program file allows read and execute access.<a name="21397">
</a>
<p></dl>
<TABLE BORDER="2" CELLPADDING="1" width="100%">
<TR><TD COLSPAN=3><P ALIGN=Center>
<IMG SRC="bluebult.gif">
<A HREF="#topofpage">
<FONT SIZE=-1>Top of Page</FONT></A>
<IMG SRC="bluebult.gif">
</TD></TR>
<TR><TD COLSPAN=3><P ALIGN=Center>
<A href="cgi-ch2.htm">
<IMG BORDER="0" src=navbprev.gif alt="[ Previous ]"></A>
<A href=toc.htm>
<IMG BORDER="0" src=navbhome.gif alt="[ Contents ]"></A>
<A href=master.htm>
<IMG BORDER="0" src=navbhelp.gif alt="[ Index ]"></A>
<A href="cgi-ch4.htm">
<IMG BORDER="0" src=navbnext.gif alt="[ Next ]"></A>
<BR align=center>
<FONT size=-1>Copyright © 1998-99 America Online,
Inc.</FONT>
</TD></TR></TABLE></BODY></HTML>
|