IIS Environment Variables

This section describes what environment variables are provided by the IIS server for CGI programs.

To know how many environment variables are provided by the Web server, and what information they are containing, I wrote the follow Perl CGI program, CgiEnv.pl.

#- CgiEnv.pl
#- Copyright (c) 1996 by Dr. Herong Yang, http://www.herongyang.com/
#
   print "Content-Type: text/html\n\n";
   print "<html><body>\n";
   foreach $var (sort keys(%ENV)) {
      print($var, ' = ', $ENV{$var}, "<br/>\n");
   }
   print "</html></body>\n";

Running it directly in a command window, I got:

Content-Type: text/html

<html><body>
ALLUSERSPROFILE = C:\Documents and Settings\All Users.WINNT<br/>
APPDATA = C:\Documents and Settings\herong\Application Data<br/>
COMMONPROGRAMFILES = C:\Program Files\Common Files<br/>
COMPUTERNAME = localhost<br/>
COMSPEC = C:\WINNT\system32\cmd.exe<br/>
HOMEDRIVE = C:<br/>
HOMEPATH = \Documents and Settings\herong<br/>
LOGONSERVER = \\localhost<br/>
NUMBER_OF_PROCESSORS = 1<br/>
OS = Windows_NT<br/>
OS2LIBPATH = C:\WINNT\system32\os2\dll;<br/>
PATH = D:\Perl\bin\;C:\WINNT\system32;C:\WINNT;...
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH<br/>
PROCESSOR_ARCHITECTURE = x86<br/>
PROCESSOR_IDENTIFIER = x86 Family 6 Model 8 Stepping 1, GenuineInte...
PROCESSOR_LEVEL = 6<br/>
PROCESSOR_REVISION = 0801<br/>
PROGRAMFILES = C:\Program Files<br/>
PROMPT = $P$G<br/>
SESSIONNAME = Console<br/>
SYSTEMDRIVE = C:<br/>
SYSTEMROOT = C:\WINNT<br/>
TEMP = C:\DOCUME~1\herong\LOCALS~1\Temp<br/>
TMP = C:\DOCUME~1\herong\LOCALS~1\Temp<br/>
USERDOMAIN = home<br/>
USERNAME = herong<br/>
USERPROFILE = C:\Documents and Settings\herong<br/>
WINDIR = C:\WINNT<br/>
</html></body>

Running it through IIS as a CGI application, I got:

ALLUSERSPROFILE = C:\Documents and Settings\All Users.WINNT
COMMONPROGRAMFILES = C:\Program Files\Common Files
COMPUTERNAME = localhost
COMSPEC = C:\WINNT\system32\cmd.exe
CONTENT_LENGTH = 0
GATEWAY_INTERFACE = CGI/1.1
HTTPS = off
HTTP_ACCEPT = */*
HTTP_ACCEPT_LANGUAGE = en-us
HTTP_CONNECTION = Keep-Alive
HTTP_HOST = localhost
HTTP_USER_AGENT = Mozilla/4.0 (compatible; MSIE 6.0; MSNIA; Windows...
INSTANCE_ID = 1
LOCAL_ADDR = 127.0.0.1
NUMBER_OF_PROCESSORS = 1
OS = Windows_NT
OS2LIBPATH = C:\WINNT\system32\os2\dll;
PATH = D:\Perl\bin\;C:\WINNT\system32;C:\WINNT;...
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PATH_INFO = /cgi-bin/CgiEnv.pl
PATH_TRANSLATED = c:\inetpub\wwwroot\cgi-bin\CgiEnv.pl
PROCESSOR_ARCHITECTURE = x86
PROCESSOR_IDENTIFIER = x86 Family 6 Model 8 Stepping 1, GenuineIntel
PROCESSOR_LEVEL = 6
PROCESSOR_REVISION = 0801
PROGRAMFILES = C:\Program Files
REMOTE_ADDR = 127.0.0.1
REMOTE_HOST = 127.0.0.1
REQUEST_METHOD = GET
SCRIPT_NAME = /cgi-bin/CgiEnv.pl
SERVER_NAME = localhost
SERVER_PORT = 80
SERVER_PORT_SECURE = 0
SERVER_PROTOCOL = HTTP/1.0
SERVER_SOFTWARE = Microsoft-IIS/5.0
SYSTEMDRIVE = C:
SYSTEMROOT = C:\WINNT
TEMP = C:\WINNT\TEMP
TMP = C:\WINNT\TEMP
USERPROFILE = C:\Documents and Settings\Default User.WINNT
WINDIR = C:\WINNT

As you can see from the output, IIS has added some and removed some environment variables in the CGI environment.

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

 Open Directories and Read File Names

 File System Functions and Operations

 Converting Perl Script to Executable Binary

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

CGI (Common Gateway Interface)

 What Is Common Gateway Interface (CGI)?

IIS Environment Variables

 QUERY_STRING - CGI Query String

 Calculator.pl - CGI Application Example

 XML-RPC - Remote Procedure Call with XML and HTTP

 RPC::XML - Perl Implementation of XML-RPC

 Integrating Perl with Apache Web Server

 CGI.pm Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

 References

 PDF Printing Version