- Irie Pascal
- Web Programming
- Company
This simple CGI program displays the contents of the standard CGI environment variables.
(********************************************************************************************
** PROGRAM : cgiinfo
** VERSION : 1.0.1
** DESCRIPTION : Displays commonly used CGI environment variables.
** AUTHOR : Stuart King
** COPYRIGHT : Copyright (c) Irie Tools, 2002-2010. All Rights Reserved.
** NOTES :
** This sample program is distributed with Irie Pascal, and is an example of how to
** write CGI programs using Irie Pascal. To make best use of this sample you should have
** a basic understanding of Pascal as well as a basic understanding of the
** Common Gateway Interface (CGI).
**********************************************************************************************)
program info(output);
procedure WriteResponseHeader;
begin (* WriteResponseHeader *)
writeln('content-type: text/html');
writeln
end; (* WriteResponseHeader *)
procedure WriteHTMLHeader;
begin (* WriteHTMLHeader *)
writeln('<head>');
writeln('<title>Irie Pascal sample CGI application</title>');
writeln('</head>')
end; (* WriteHTMLHeader *)
procedure WriteHTMLBody;
procedure DisplayEnvVar(name : string);
var
value : string;
begin (* DisplayEnvVar *)
value := getenv(name);
writeln(name, ' = ', value, '<br>')
end; (* DisplayEnvVar *)
begin (* WriteHTMLBody *)
writeln('<body>');
writeln('<h1>This program displays the contents of the CGI environment variables.</h1>');
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');
(* Don't show this one for security purposes
DisplayEnvVar('SERVER_SOFTWARE');
*)
writeln('</body>')
end; (* WriteHTMLBody *)
procedure WriteHTMLFooter;
begin (* WriteHTMLFooter *)
end; (* WriteHTMLFooter *)
begin
WriteResponseHeader;
writeln('<html>');
WriteHTMLHeader;
WriteHTMLBody;
writeln('</html>')
end.
This program is included with Irie Pascal (in the samples directory).
The program works as follows:
WriteResponseHeader
WriteResponseHeader
writes the HTTP response header:
content-type: text/html
which tells the client (usually a web browser) that the content of the response is a html text file.
Notice that the built-in procedure writeln
is used to write the response header
to the standard output stream, and on to the waiting web server.
Notice also the second writeln
, which is used to write a blank line after
the response header. The blank line tells the web server that the response header is finished, and that what
follows is the response file.
writeln('<html>');
writeln('<html>');
writes the open html tag
(marking the beginning of the html response file).
WriteHTMLHeader
WriteHTMLHeader
writes a html header (containing just a title).
WriteBody
WriteBody
writes the open body tag
<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.
writeln('</html>');
writeln('</html>');
writes the close html tag
(marking the end of the html response file).
When the program ends, the web server sends all of output to the client
CGIInfo has been compiled and installed on this server. Click info.cgi.