“Would you tell me, please, which way I ought to go from here?” “That depends a good deal on where you want to get to,” said the Cat. Alice in Alice’s Adventures in Wonderland by Lewis Carroll The Cheshire Cat was renowned for oblique comments and a propensity to vanish partially or completely at inconvenient times. Running Common Gateway Interface (CGI) programs through a Web server can leave one feeling a lot like Alice (including stretched thin and squashed). 13.1 CGI A glance at comp.lang.perl.misc reveals that many people don’t understand the difference between the CGI protocol and the Perl scripts that use it. We therefore consider it our civic duty to take the time to explain it here, even though we’re talking about something that is not Perl. (That’s the Perl connection that it has nothing to do with Perl. It’s all very G del-like.) The Common Gateway Interface is a specification for how a Web server can deliver dynamic content. It says that you can have a URL that points not to a static file but to a program whose output will be sent to the browser. The user of the browser cannot tell the difference between a CGI program and a static file by looking at what the server returns; the only clue is that the URL usually looks different. (Instead of ending in .html, it probably ends in .cgior contains /cgi-bin/. There’s nothing hard and fast about this rule though. It’s easy to configure a Web server to return static pages whose URLs look like CGI programs, and vice- versa.) The point, however, is that they shouldn’t care what produced the output. The CGI specification spells out how a program invoked in this way can have inputs sent by a browser (as part of the URL using an HTTP GET command or in HTTP content with a POST command), how the program can see those inputs (in the QUERY_STRINGenvironment variable or in their standard input respectively), how the inputs are encoded (a
Hint: This post is supported by Gama besplatan domen provider