CGIInfo.pas
The following example CGI program is included with Irie Pascal (look in the samples
directory). A brief description, of how this program works, follows the program listing
below.
program info(output);
procedure WriteHeader;
begin
writeln('Content-type: text/html');
writeln;
writeln('<html>');
writeln('<head>');
writeln('<title>Irie Pascal sample CGI application</title>');
writeln('<h1>CGI environment variables.</h1>');
writeln('</head>')
end;
procedure WriteBody;
procedure DisplayEnvVar(name : string);
var
value : string;
begin
value := getenv(name);
writeln(name, ' = ', value, '<br>')
end;
begin
writeln('<body>');
DisplayEnvVar('HTTP_ACCEPT');
DisplayEnvVar('HTTP_ACCEPT_ENCODING');
DisplayEnvVar('HTTP_ACCEPT_LANGUAGE');
DisplayEnvVar('HTTP_AUTHORIZATION');
DisplayEnvVar('HTTP_CHARGE_TO');
DisplayEnvVar('HTTP_FROM');
DisplayEnvVar('HTTP_IF_MODIFIED_SINCE');
DisplayEnvVar('HTTP_PRAGMA');
DisplayEnvVar('HTTP_REFERER');
DisplayEnvVar('HTTP_USER_AGENT');
writeln('<hr>');
DisplayEnvVar('AUTH_TYPE');
DisplayEnvVar('CONTENT_LENGTH');
DisplayEnvVar('CONTENT_TYPE');
DisplayEnvVar('GATEWAY_INTERFACE');
DisplayEnvVar('PATH_INFO');
DisplayEnvVar('PATH_TRANSLATED');
DisplayEnvVar('QUERY_STRING');
DisplayEnvVar('REMOTE_ADDR');
DisplayEnvVar('REMOTE_HOST');
DisplayEnvVar('REMOTE_IDENT');
DisplayEnvVar('REMOTE_USER');
DisplayEnvVar('REQUEST_METHOD');
DisplayEnvVar('SCRIPT_NAME');
DisplayEnvVar('SERVER_NAME');
DisplayEnvVar('SERVER_PORT');
DisplayEnvVar('SERVER_PROTOCOL');
DisplayEnvVar('SERVER_SOFTWARE');
writeln('</body>')
end;
procedure WriteFooter;
begin
writeln('</html>')
end;
begin
WriteHeader;
WriteBody;
WriteFooter
end.
|
This simple CGI program displays the contents of the standard CGI environment
variables. This application calls WriteHeader, then WriteBody,
and finally WriteFooter. WriteHeader writes the response
header as well as the first part of the html file. Just as in the case of the first CGI
sample application cgihello.pas the response header is
content-type: text/html
And again the required blank line separates the response header from the html response
file.
WriteBody writes
<body>
to indicate the start of the body of the html file. WriteBody then
makes repeated calls to WriteEnvVar, to display the contents of the
standard environment variables. Finally WriteBody writes
</body>
to indicate the end of the body of the html file.
NOTE: DisplayEnvVar uses the built-in function getenv
to read the contents of the environment variables.
WriteFooter then writes
</html>
to indicate the end of the html file.
The web server sends all of this to the client (after completing the response header).
This program has been compiled and installed on this server. To see it run, click here.
Next > Redirect |