Giovanni's logo
Retrieve HTTP server environment variables
this means Version 2
power search
blue line
You may retrieve the value set by the server for a particular HTTP environment variable by using Mel's prototyped procedure GetEnv. This procedure calls QtmhGetEnv API.

QtmhGetEnv API provides information about the following HTTP Server environment variables:
(for a complete list of the environment variables set by the HTTP server, see this page)
Environment variable Meaning
AUTH_TYPE If the server supports client authentication and the script is a protected script, this environment variable contains the method that is used to authenticate the client. For example: Basic
CGI_ASCII_CCSID Contains the ASCII CCSID the server used when converting CGI input data. If the server did not perform any conversion, (for example, in %%BINARY%% mode), the server sets this value to the DefaultNetCCSID configuration directive value
CGI_MODE Contains the CGI conversion mode the server is using for this request. Valid values are %%EBCDIC%%, %%MIXED%%, %%BINARY%%, or %%EBCDIC_JCD%% (for more information, see HTTP Server for AS/400 Webmaster's Guide). The program can use this information to determine what conversion, if any, was performed by the server on CGI input data and what format that data is currently in
CGI_EBCDIC_CCSID Contains the EBCDIC CCSID under which the current server job is running (DefaultFsCCSID configuration directive). It also represents the current job CCSID that is used during server conversion (if any) of CGI input data
CONTENT_LENGTH When the method of POST is used to send information, this variable contains the number of characters. Servers typically do not send an end-of-file flag when they forward the information by using stdin. If needed, you can use the CONTENT_LENGTH value to determine the end of the input string. For example: 7034
CONTENT_TYPE When information is sent with the method of POST, this variable contains the type of data included. You can create your own content type in the server configuration file and map it to a viewer. For example: Application/x-www-form-urlencoded
GATEWAY_INTERFACE The version of the CGI specification with which the server complies. Format: CGI/revision
HTTP_ACCEPT MIME content types the browser will accept.
HTTP_COOKIE All the cookies available to the current page.
HTTP_HOST Contains the HTTP host URL.
HTTP_REFERER Reference to the page or frame the current page or frame was linked from
HTTP_USER_AGENT String identifying the Web client. Includes name and version of the browser, request made through a proxy, and other information.
IBM_CCSID_VALUE The CCSID under which the current server job is running.
PATH_INFO The extra path information following the path information required to identify the CGI program name.
PATH_TRANSLATED The server provides a translated version of PATH_INFO, which takes the path and does any virtual-to-physical mapping to it.
QUERY_STRING Anything that follows the first ? in the request URL. The string is encoded in the standard URL format of changing spaces to '+" and encoding special characters with '%xx' hexadecimal encoding.
REMOTE_ADDR The IP address of the remote host making the request
REMOTE_HOST The hostname making the request.
REMOTE_IDENT User ID of the remote user.
REQUEST_METHOD The method with which the request was made. For HTTP, this is GET or POST.
REMOTE_USER If you have a protected script and the server supports client authentication, this environment variable contains the user name that is passed for authentication
SCRIPT_NAME A virtual path to the program being executed, used for self-referring URLs.
SERVER_ADDR The server's IP address
SERVER_NAME The server's hostname, DNS alias, or IP address as it would appear in self-referring URLs
SERVER_PORT The port number to which the request was sent.
SERVER_PROTOCOL The name and revision of the information protocol this request came in with. Format: protocol/revision
SERVER_SOFTWARE The name and version of the information server software answering the request (and running the gateway). Format: name/version.
For example:
IBM-Secure-ICS/AS/400 Secure HTTP Server

In CGIDEV2 you may find two CGI programs that retrieve environment variables:
  • program ENVVAR retrieves the most common HTTP server environment variables.
  • program DSPENVVAR let's you display all the HTTP server environment variables, both non-SLL and SSL specific, plus some Java environment variables.

Example: the environment variable SERVER_PROTOCOL

 /copy mysrclib/qrpglesrc,hspecs
 /copy mysrclib/qrpglesrc,hspecsbnd
 * Variables common to all CGIs
 /copy mysrclib/qrpglesrc,prototypeb
 /copy mysrclib/qrpglesrc,usec
 /copy mysrclib/qrpglesrc,variables3
 *          ... etc. ...
 * Server's Protocol
C                   eval      S_Protocol =getenv('SERVER_PROTOCOL':
C                             qusec)