Business Directory
Trade Forum
Vision 2000
Delphi
Domain Rates
Search
Music
Opinion Award
About
FeedBack
Quit


Delphi Internet

| Tips & Tricks | Bug List | Cool Delphi Sites |
| Connectivity | Delphi 2.0 Features | Internet |

What happens when a CGI script is called?

The following diagram briefly outlines the machinations that underlie a typical CGI transaction. The browser triggers an event -- usually through a form submission -- that causes the WWW server to execute a program rather than return an HTML document.

The server packages the pertinent CGI information and the client's data and outputs it to a file in a temporary directory. The name of the file is passed as a parameter to the CGI executable. If the CGI script is entitled POSTDATA.EXE, then the information that is passed by the server to the operating system could be conceptualized as follows. . . "postdata tempfilename".

Your CGI program can read the tempfilename as from parameter string, that's how the CGI program learns where to look for the client data. That temp file also passes a suite of other important facts to your program, including the name of the output file and where the server expects to find the data when you are done processing it.

Your code reads the data out of the temp file.

When you are done processing the data, your results are written to the temporary output file.

When the server detects that the process has finished running, it reads the temp file, passes the data to the browser, and then erases the temp file.

The Temp File

The listing below is taken from an actual temp file that was created on my system. The name of the file was C:\TEMP\63WS.INI -- the name was assigned by WebSite. Note that this is the normal INI structure with [SECTION HEADINGS] in brackets and key=value pairs listed in their respective sections. If you look in the [FORM LITERAL] section you will see that the browser filled out a form that asked for name and email information.

In the [SYSTEM] section you will find the input and output file name; my CGI script read the data right out of the key value pairs in this file, I did not read the 63WS.INP file. I returned my data to 63WS.OUT.

[CGI]
Request Protocol=HTTP/1.0
Request Method=POST
Executable Path=/cgi-win/eecgi.exe
Server Software=WebSite/1.0c (demo version)
Server Name=206.148.128.17
Server Port=80
Server Admin=eezis@mail.lm.com
CGI Version=CGI/1.2 (Win)
Remote Address=206.148.128.17
Referer=http://206.148.128.17/cgitest3.htm
Authentication Method=Basic
Authentication Realm=Web Server
Content Type=application/x-www-form-urlencoded
Content Length=46
[System]
GMT Offset=-18000
Debug Mode=No
Output File=c:\temp\63ws.out
Content File=c:\temp\63ws.inp
[Form Literal]
First=Ernest
Last=Ezis
email=eezis@mail.lm.com
[Accept]
image/gif=Yes
image/x-xbitmap=Yes
image/jpeg=Yes
image/pjpeg=Yes
*/*=Yes
[Extra Headers]
Connection=Keep-Alive
User-Agent=Mozilla/2.0b4 (WinNT; I)
Host=206.148.128.17

Summary

As you can see the process is relatively simple. The browser (probably Netscape) triggers WebSite to execute a script. WebSite calls the executable file and passes it the CGI data in a temp file. The CGI executable reads the temp file, processes the data and writes its output to a temp file. When WebSite detects that the CGI script has ceased (it finds the expected output file returned by the CGI code), it retrieves the data from the executable and then sends the data to the browser. Don't worry about the details yet, just try to visual a figurative model for the major steps.

| Borland Delphi | About the Authors | Home |

For Queries Mail To Webmaster

Copyright © 1996 Asylum Software Pvt. Ltd. This is an ASPL production.
Produced in conjunction with ASPL DELPHI TEAM.
Last revised November 27, 1996.