Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: CGI program

by saberworks (Curate)
on Sep 23, 2009 at 16:16 UTC ( #797016=note: print w/replies, xml ) Need Help??

in reply to CGI program

There seems to be some misunderstanding of what CGI is and how it's utilized. Some people say it's just the way you pass parameters to and from scripts (url?some_var=some_val), but my understanding is that this is wrong. CGI is a specification for your web server to communicate with your script. The way it communicates is by a series of environment variables guaranteed to be there and with specific uses. For example, QUERY_STRING, REQUEST_METHOD, etc. These are all listed in the RFC.

The nice thing about programming perl for CGI is that we have the nifty CGI module (or any of the other, smaller ones) that examines all those environment variables and provides functional or OO interfaces to the relevant information they contain. So instead of having to parse $ENV{'QUERY_STRING'} manually, the CGI module does it for us. In addition, the CGI specification provides a way to access things like the server name, the script name, the remote host, etc.

The RFC describes this succinctly:
The server acts as an application gateway. It receives the request from the client, selects a CGI script to handle the request, converts the client request to a CGI request, executes the script and converts the CGI response into a response for the client. When processing the client request, it is responsible for implementing any protocol or transport level authentication and security. The server MAY also function in a 'non-transparent' manner, modifying the request or response in order to provide some additional service, such as media type transformation or protocol reduction.

Replies are listed 'Best First'.
Re^2: CGI program
by manishrathi (Beadle) on Sep 23, 2009 at 17:49 UTC
    Are these variables part of web server or are they defined by CGI ? I am um=nder thye impression that these varibles are defined as environment variables by the web server environment.
    AM I correct , or are these variables specified by the CGI only and when a CGI is used in a program , only at thah time these variables can be used in a program ? If these variables are specified by the web server, then why can they not be used in the script directly ? Why do we have to use CGI to get these values in the script ? thanks

      The CGI specification requires the web server to set these environment variables. The script is then free to do with these variables what it wants.

      You don't need to use the module to access these variables, but it provides a convenient way to do it.

      Perl 6 - links to (nearly) everything that is Perl 6.
        Are these variables created by web server, irrespective of whether CGI API is used in a script or not or are they created only when CGI API is used by a script ?
        These variable get their names only after they web server creates them and assigns values. But how are they named , when they are received by the webserver ? For example, will QUERY_STRING have different name before its named by web server ?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://797016]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2021-03-07 12:41 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (121 votes). Check out past polls.