How CGI Scripts Work
- Your browser requests an Internet document from the web server.
- The web server software finds the document.
- The web server software sends the document to your browser.
- Your browser displays the requested document.
But how does the web server software know what to do with the information it receives from the HTML form? The information on the HTML form could be sent to an email address. (This is what our WISCO Survey Power software does.) The information could also be added to a database stored on the Internet. The web server software, by itself, can not know which information to include in an email, or the email address to receive the information. The web server software, by itself, can not know how to verify every piece of information before it is added to different Internet databases. An additional program, located on the web server, is needed to process the HTML form information. The web server also needs to know which web program will process the HTML form information. The extra information needed by the web server software is sent with the form information when a user clicks the submit button on the HTML form. Web programs that process HTML form information are known as "Common Gateway Interface" programs, or CGI scripts. Basically, the following steps occur when a form is displayed:
- Your browser requests an Internet form document from the web server.
- The web server software finds the form document.
- The web server software sends the form document to your browser.
- The respondent completes the form, and clicks the submit button.
- The web server software passes the HTML form information to the CGI script.
- The CGI script/program executes a series of instructions to process to data.
- After the data is processed, the CGI script can create an HTML "Thank You" page for the web server to get.
- The web server software sends the "Thank You" page to your browser.
- Your browser displays the "Thank You" page created by the CGI script.
Many programming languages can be used to create CGI programs, but some can only be used after they have been compiled. Perl CGI scripts do not have to be compiled, so they are easier to debug, modify, and maintain. For these reasons, Perl is the most popular programming language for writing CGI scripts. Perl is also freely available, and will run on every computer platform that can host an Internet web server. CGI scripts can request any kind of information that can be stored in a file. (for example text, graphics, sound and video files, URL's, etc.) The CGI scripts can send the information to databases, other documents, and to other programs for further processing. For security reasons, all CGI scripts and programs must be placed in a special directory (usually /cgi-bin) on the Internet web server. CGI Script Mailers
CGI scripts that send the formatted information from an HTML form to an email address are called mailers. Two common free open source web email CGI scripts are FormMail and sendmail. FormMail is used on a Unix web server. FormMail is one of the most-used generic web server CGI scripts. It is also the easiest of the three CGI scripts to use. Formmail only sends the email. It does not verify any HTML form information. Blat.exe, also known as FormMail for Windows, is used on Windows NT and Windows IIS servers. Blat.exe requires an additional custom CGI script to create a temporary text file that blat.exe sends as an email. Blat.exe does not verify any HTML form information. For security reasons, some ISP's will not allow blat.exe on their web servers because the sender's email address can be forged and used to send unsolicited commercial email (spam). The WISCO Survey Power software removed support for blat.exe with version 6 as Microsoft CDONTS and CDOSYS provide better security. Sendmail is a CGI script that can also be used on Unix servers. The WISCO Survey Power software automatically creates a complete Perl CGI script to match your survey questions. This Perl CGI script can include instructions to verify the responses to the survey questions, and return error messages to the user. The user can correct the HTML form information before re-clicking the submit button. After the HTML form information is verified, the Perl CGI script labels and formats the survey responses so the WISCO Survey Power software can interpret the responses. The formatted responses are passed to the sendmail CGI script. Sendmail creates an email, and sends the formatted responses to the designated email address. Perl CGI scripts with error checking features for use with sendmail is included in the current version of the WISCO Survey Power software.