Common Gateway InterfaceThis document gives a general overview of how the common gateway interface works. Please refer to the documentation of your web server for more specific details. Web Servers A web server is a program that will return documents requested using the HTTP protocol. In its most simplest form a directory on the web server acts as the DocumentRoot and when ever a file is requested it is taken from this document root. For example, if c:\my documents\my web\ was the document root on the web server www.mycompany.com, then http://www.mycompany.com/help/index.html would send a request to www.mycompany.com for the file help/index.html and the web server would return c:\my documents\my web\help\index.html Aliases In practice things are normally a little more complicated. As well as a document root, the configuration files of a web server will normally specify a number of aliases. An alias specifies that requests for files in certain directories should look in different physical directories. For example /dave/* should look in c:/users/dave/html/*. When you configured the Gsharp Web Edition, you should have configured a number of aliases:
Scripts It is possible to configure your web server to say that certain files are not HTML files, but scripts. The script should be run by the web server; should capture the HTML that it outputs and thensend that back instead. As scripts are created in real time, they can be used to make dynamic content. HTML pages that can adapt in real time to the latest data and/or to user input. There are a number of ways that you can specify that a file is a script rather than an HTML file. You could for example say that anything with the extension .cgi or anything in a specified directory is a script. Most web servers are set up with a directory called /cgi-bin/ which it expects to contain scripts. The Gsharp-bin alias mentioned above should have been specified as a directory for scripts. Running Scripts The file run by the web server can be any sort of script or executable. The web server does not parse the file, it just runs it and captures whatever it sends to stdout. If the file is a script, written in perl or GSL, then the appropriate program to run the script must be installed on the machine. On UNIX, the file should also have execute permission. The first line of the script is normally used to specify which program should be used to parse it. e.g. #!/bin/perl or #!/bin/GsharpWE. Some Windows web servers can be configured to use the program associated by Windows instead of the #! line. A good test to see that your script has been configured correctly is to start a shell and to run the script from the command line. The script should run and sent HTML to the screen. Content Type The first line output by the script must specify the format of the file that is being created. This is normally "text/html", but it could be something like "image/gif". The first line must be followed by a blank line. In Gsharp you could use something like this: echo("Content-type: text/html");
echo("");
Form Input When a form is created in HTML it is possible to specify a script that will process the output of the form. The values in the form are passed to the script in one of two ways depending on the METHOD specified in the form. The POST method puts the form values into the environment and the GET method send them via stdin. The script will normally have to parse this information to find the values of the form fields. If you are using Gsharp Web Edition, then it parses the information for you and stores the fields in string datasets called FORM_name, where name is the name of the field. So for example a field called height will be made available in FORM_height. |