from which CGI scripts take their name. CGI is an application protocol that web servers
use to transfer input data and results between web browsers and other clients and
server-side scripts. Perhaps a more useful way to understand CGI, though, is in terms
of the interaction it implies.
Most people take this interaction for granted when browsing the Web and pressing
buttons in web pages, but a lot is going on behind the scenes of every transaction on
the Web. From the perspective of a user, it’s a fairly familiar and simple process:
Submission
When you visit a website to search, purchase a product, or submit information
online, you generally fill in a form in your web browser, press a button to submit
your information, and begin waiting for a reply.
Response
Assuming all is well with both your Internet connection and the computer you are
contacting, you eventually get a reply in the form of a new web page. It may be a
simple acknowledgment (e.g., “Thanks for your order”) or a new form that must
be filled out and submitted again.
And, believe it or not, that simple model is what makes most of the Web hum. But
internally, it’s a bit more complex. In fact, a subtle client/server socket-based architec-
ture is at work—your web browser running on your computer is the client, and the
computer you contact over the Web is the server. Let’s examine the interaction scenario
again, with all the gory details that users usually never see:
Submission
When you fill out a form page in a web browser and press a submission button,
behind the scenes your web browser sends your information across the Internet to
the server machine specified as its receiver. The server machine is usually a remote
computer that lives somewhere else in both cyberspace and reality. It is named in
the URL accessed—the Internet address string that appears at the top of your
browser. The target server and file can be named in a URL you type explicitly, but
more typically they are specified in the HTML that defines the submission page
itself—either in a hyperlink or in the “action” tag of the input form’s HTML.
However the server is specified, the browser running on your computer ultimately
sends your information to the server as bytes over a socket, using techniques we
saw in the last three chapters. On the server machine, a program called an HTTP
server runs perpetually, listening on a socket for incoming connection requests and
data from browsers and other clients, usually on port number 80.
Processing
When your information shows up at the server machine, the HTTP server program
notices it first and decides how to handle the request. If the requested URL names
a simple web page (e.g., a URL ending in .html), the HTTP server opens the named
HTML file on the server machine and sends its text back to the browser over a
What’s a Server-Side CGI Script? | 1127