?? ch9.htm
字號:
<HTML><HEAD><TITLE>Chapter 9 -- How Common Gateway Interface (CGI) Works</TITLE><META></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910"><H1><FONT SIZE=6 COLOR=#FF0000>Chapter 9</FONT></H1><H1><FONT SIZE=6 COLOR=#FF0000>How Common Gateway Interface (CGI)Works</FONT></H1><HR><P><CENTER><B><FONT SIZE=5><A NAME="CONTENTS">CONTENTS</A></FONT></B></CENTER><UL><LI><A HREF="#HowCommonGatewayInterfaceCGIWorks">How Common Gateway Interface (CGI) Works</A></UL><HR><P>In general, Web software is not particularly database friendly-itoften happens that valuable corporate information is not alwaysaccessible to many people who need it.<P>In the earliest days of the Web, it was exceedingly difficultfor anyone to gain access to those databases. As technology developed,however, and it became easier to access databases, an increasingnumber of databases became available, both on the Internet andthen later on intranets as well. Web server software was developedto make it easier to access databases for the Web.<P>There are a number of ways in which someone from an intranet cantap into corporate databases. An exceedingly popular one is calledthe <I>Common Gateway Interface</I> (CGI). CGI allows any executableto run and have its output sent back to the requesting client.Therefore, it allows intranet programmers to write programs andscripts that will allow people on an intranet to use their Webbrowsers to easily query databases by filling out forms on Webpages-and they will then send those results back in HTML formthat the browsers can understand.<P>Essentially, CGI is an interface that delivers information fromthe server to your program and from your program back to the requestingclient. It is not a programming language. The program does allthe processing. CGI only gets data to the program. On an intranet,the data accessed is often from a database of some sort. You'veno doubt used CGI many times without knowing it. On the Internet,for example, if you've filled out a form on a Web page in orderto register to use a site, and then later received an e-mail notificationwith a password for you to use, you've probably used CGI. CGImost likely took the information you filled in the form, performedseveral actions on it (including putting the information in adatabase), automatically created a password, and then automaticallysent you mail.<P>On your corporate intranet, if you have one, you may well haveused CGI programs or scripts as well. If you've queried a corporatedatabase from a Web page and gotten information from it, thenthere's a good chance that a CGI program or script is what didthe work for you.<P>Intranet programmers can use a variety of technologies to makeuse of CGI. One of the simplest is to use what's called an <I>interpretedlanguage</I>. An interpreted language, such as the popular Perlused on UNIX systems, is often favored because scripts writtenwith them are easy to debug, modify, and maintain.<P>CGI can also be accessed with more sophisticated computer languages,such as C, C++, or Fortran. When a programmer writes a programin a language such as C to be accessed by CGI, the program mustfirst be <I>compiled</I>. That means running it through a programcalled a compiler that can change the application into a machine-readablelanguage that the computer can understand.<H2><A NAME="HowCommonGatewayInterfaceCGIWorks"><FONT SIZE=5 COLOR=#FF0000>How Common Gateway Interface (CGI) Works</FONT></A></H2><P>Essentially, CGI is an interface that delivers information fromthe server to your program and from your program back to the requestingclient. It is not a programming language. The program does allthe processing. CGI only gets data to the program. CGI is a standardthat allows programmers to write programs that can access informationservers and databases, and then send the information to userson an intranet. Using CGI, Web-based intranet technologies cancommunicate with non-TCP/IP resources and databases. Using CGI,an intranet programmer can write an application that searchesa database and displays the result in HTML format. CGI is usedto allow people to fill out corporate forms on an intranet, andhave that information entered into a database. <OL><LI>For CGI to be used, an intranet programmer first writes aprogram or a script. Since interpreted languages are easier todebug, modify, and maintain than compiled programs, they are usedmore frequently than compiled programs. Perl is probably the mostpopular language for writing scripts. Languages such as C, C++,or Fortran can be used to access CGI as well after they have beencompiled.<LI>Next, the script or compiled program is put on an intranetWeb server in a special directory (usually called /cgi-bin) whichholds all the CGI programs and scripts. For security reasons,programs put in other directories won't run. If multiple directoryplacements were allowed, it would be difficult for intranet maintainersto track them all and therefore realize if an unauthorized userposted a rogue CGI program.<LI>After posting the CGI program to /cgi-bin, it is linked tothe URL in HTML on an intranet Web page.<LI>When someone clicks on the URL, the server launches (via HTML'sGET or POST) the CGI program residing on the Web server. If, forexample, the CGI program's function is for searching a database,the CGI program could send an HTML form to the client. From theclient, the data on the completed query form is sent (with HTTPrequest headers) back to the CGI program using STDIN or environmentvariables. The data is formatted as encoded name/value pairs.<LI>The CGI program contacts the database and requests the information.The database sends the information to the CGI program. The informationcan be in a variety of formats, such as text, graphics, soundand video files, and URLs. The CGI program returns the resultsto the server (via STDOUT) which, in turn, would send it on tothe browser.<LI>The CGI program also formats the data, for example, takingthe information and putting it into HTML format so that the usercan read it using a Web browser. The user can use that HTML pageas they can any other.</OL><HR><CENTER><P><A HREF="ch8.htm"><IMG SRC="PC.GIF" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="#CONTENTS"><IMG SRC="CC.GIF" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="contents.htm"><IMG SRC="HB.GIF" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="ch10.htm"><IMG SRC="NC.GIF" BORDER=0 HEIGHT=88 WIDTH=140></A><HR WIDTH="100%"></P></CENTER></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -