(044) 362 48 16 (098) 294 41 60
|
|
|
Example 1 To understand how the CGI to create two simple examples that run on Vindovze. To get started, make sure that Apache understands the CGI, to find that some such lines, and if not, it will create:
ScriptAlias / cgi-bin / "C: / apache / www/ cgi-bin / " <Directory "C:/apache/www/cgi-bin"> AllowOverride None Options None Order allow, deny Allow from all </ Directory> Then run Borland Pascal and write a programku:
uses dos; var i: integer; begin writeln ( 'Content-type: text / html'); writeln; writeln ( 'This is an example of CGI program.'); writeln ( 'Here is list of environment variables available for you'); writeln ( '<pre>'); For I: = 1 To EnvCount Do WriteLn (EnvStr (I)); writeln ( '</ pre>'); end.
Compile it (Alt + F9 or Ctrl + F9) and put the *. exe file in the folder C: / apache / www / cgi-bin /. Then open a browser and enter the address
http://localhost/cgi-bin/example.exe?var1=value1&var1=value2 A list of available variabless environment. Theoretically, even in Pascal, you can write programs of any complexity, but for this project, the tools are clearly mean.
Example 2 Create a batch file run.bat
@ echo off echo Location: / cgi-bin/example.exe
http://localhost/cgi-bin/run.bat all that he returns - it redirects to the program from Example 1.
Results So, we saw that the CGI program can run a web server (Apache, IIS) in two ways:
- This is interpreted (batch) file, run the associated program and, as a parameter - the batch file.In this way, working PHP and Perl, if installed as a CGI.
From the web server knows how to run the program This is very different to the Wind and * Nix.
- At Wind Web Server is watching the file extension (this is typically the last charactersto the first point from the end). If it is *. exe or *. com file that runs as an executable. If the *. bat (and *. cmd on WinNT) then run command interpreter DOS command.com (cmd.exe on WinNT) file as a parameter. If the Web server IIS, you can also start and *. dll program. If fayl has other extensions, the Web server first looks in its configuration (httpd.conf etc) there is no registered extensions. If no, the more he looks into the registry Vindouz. Apache does so only if a directive
<b> ScriptInterpreterSource & lt; / b> registry If the above option is not displayed (by default it is in
<b> ScriptInterpreterSource </ b> script ), He attempts to read the first line of the file and find tons зв. intro line (shebang line): #! c: / program files / perl / perl which indicates what you need to handle the file. If nothing is found, the output error.
- On * nix server executable files usually begin with the characters. ELF These files can be immediately processed kernel OS. In v.by the case of the file extension is found in your server (httpd.conf,. htaccess). If it's not there, searched string as an introduction to windsurfing. If your windsurfing is only one embedded interpreter (command.com), which is not very suitable for writing Web applications, it * nix'y offer you a wideBor Shell (family of shells): Bourne-shells, C-shells, Korn-shells with all their followers.
On WinNT, and * nix, except that executable files must be labeled as such, ie current user must have the performance rights (chmod 700 etc). |
|