Solved

CGI with Delphi - Output written to a file

Posted on 1998-03-11
4
373 Views
Last Modified: 2013-11-18
I am working on a CGI program written in Delphi. It accesses a database.  From what I have read and the examples I have seen, data is sent back by first writting it to an output file on the server.  From what I understand ( I am new at this ), the output file name is specified in the an INI file on the server.  Therefore, the output file is always the same.  So what happens if two peoples use the CGI program at the same time ? Do they both write to the same output file and overwrite each other or would there be an error returned ?

Also, I am just starting to read about ISAPI. Is it better ?
0
Comment
Question by:skylinka
  • 2
4 Comments
 

Author Comment

by:skylinka
ID: 1360424
Edited text of question
0
 
LVL 3

Expert Comment

by:williams2
ID: 1360425
Ok my friend, I've got know exactly what you want!
1. The HTML file first:
<html><title>Testing CGI</title><body>
<form action="http://localhost/cgi-win/test.exe" method=post>
Søgeord:
<input type= text name= searchfield1 size=20><br>
<input type=submit value="Søg">
</form></body></html>

This you have probably seen before, the Test.exe is placed in the  CGI-WIN folder (Using Website Server).
The produced INI file is given to the EXE file (Read it with  ParamStr(1) ). The INI file contains:

 [CGI]
 Request Protocol=HTTP/1.0
 Request Method=POST
 Request Keep-Alive=No
 Document Root=C:\WEBSITE\HTDOCS\
 Executable Path=/cgi-win/test.exe
 Server Software=WebSite/1.1e
 Server Name=10.2.100.138
 Server Port=80
 Server Admin=Williams@aabc.dk
 CGI Version=CGI/1.3 (Win)
 Remote Address=127.0.0.1
 Referer=file://www.aabc.dk/Test.htm
 User Agent=Mozilla/3.01 [da] (Win95; I)
 Content Type=application/x-www-form-urlencoded
 Content Length=81
 
 [System]
 GMT Offset=3600
 Debug Mode=No
 Output File=C:\Website\CGI-Temp\43ws.htm
 Content File= C:\Website\CGI-Temp\43ws.inp
 
 [Form Literal]
 searchfield1=Thomas

 [Accept]
 image/gif=Yes
 image/x-xbitmap=Yes
 image/jpeg=Yes
 image/pjpeg=Yes
 */*=Yes

 [Extra Headers]
 Host=localhost

The Outputfile will contain the string: "C:\Website\CGI-Temp\43ws.htm"
This means, that you have to write to axctly that filename. The Server program will handle it afterwards.
The "43ws.INP" contains the inputinformation from the user, but you allready got them here under the [Form Litteral] topic.

And now to the program example:

Program Test;

Uses IniFiles;

  Procedure ProcessScript;
  var
     IniFile: TInifile;
     filename: string;
     f: Textfile; //Same as 'File of Text'
  begin
     IniFile:= TInifile.create(Paramstr(1)); // Paramstr(1)

     // *** header begin ***

     filename:= IniFile.Readstring('System','Output File','');
     assignfile(f,filename);
     rewrite(f); // Create output file
     writeln(f,'HTTP/1.0 200 OK');
     writeln(f,'Date: Friday, 28 Nov-97, 13:36:12 GMT');
     writeln(f,'Server:Website/1.1e');
     writeln(f,'Allow-ranges: bytes');
     writeln(f,'Content-type: text/html');
     writeln(f,'Content-length: 0');
     writeln(f);
     writeln(f,'<HTML>');
     writeln(f,'<Title>Result</Title>');
     writeln(f,'<Body>');
     writeln(f,'<body background = http://mis.lamar.edu/mis/Grundy/parchmen.gif>');
     writeln(f,'The following matched the query: <BR><BR>');

     // *** header end ***

     GetData(IniFile); // Hand over the Inifile to the 'GetData' procedure, to finish the query.
     WriteResult(f);

     writeln(f,'</body>');
     writeln(f,'</HTML>');
     Closefile(f);
  end;

Begin
  ProcessScript;
end.

As you see, the file to be read/written is NOT THE SAME, they should actually be rather distinguished from each other. You can freely decide what to send back.

If you like more information, I can supply in the building of both DDE-Servers etc. (It's rather slow opening and initializing a DBase and close it down every time, and it's ressource demanding too. The Server will keep it open!)
0
 

Expert Comment

by:ymailhot
ID: 1360426
Thank you for your answer. My concern is if two peoples run the CGI at the same time and therefore write to the same output file. Is that possible ?
0
 
LVL 3

Accepted Solution

by:
williams2 earned 100 total points
ID: 1360427
Yes! ..That's exactly what I mean! ..The Server provides a unique name for the outputfile, namely the outputfile specified in the .INI file. I've been testing this running up to 10 queries at the same time in different varities. The outputfilename is NOT trivial, it's ALWAYS different. That you don't need to take care of, it's provided by the service in generel.

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now