Learn from sources
       star Member ENVVAR in CGIDEV2 / QRPGLESRC

       *********************************************************************
       *  RPG ILE MODULE CGIDEV2/ENVVAR
       *
       *  After compiling this RPG MODULE,
       *  create the related program with the following command:
       *
       * CRTPGM CGIDEV2/ENVVAR MODULE(CGIDEV2/ENVVAR)
       *        ACTGRP(ENVVAR) AUT(*USE)
       *
       *********************************************************************
       * MAIN PROGRAM FLOW
       *
       * 1 - Receives html input, but doesn't care
       * 2 - Retrieves all environment variables
       * 3 - Substitutes all environment variable values into
       *     html output skeleton, member ENVVAR
       *     in source file CGIDEV2/DEMOHTML,
       * 4 - writes html output section «as400»all
       *     and quits.
       *********************************************************************
       /copy CGIDEV2/qrpglesrc,hspecs
       /copy CGIDEV2/qrpglesrc,hspecsbnd
       *--------------------------------------------------------------------
       * Variables common to all CGIs
       *--------------------------------------------------------------------
       /copy CGIDEV2/qrpglesrc,prototypeb
       /copy CGIDEV2/qrpglesrc,usec
       /copy CGIDEV2/qrpglesrc,variables1
       *--------------------------------------------------------------------
       * Variables specific to this program
       *--------------------------------------------------------------------
      DNotAvail         S            256A   INZ('«I»Not available«/I»')          File containing
      D HTTP_HOST       s            256a
      D REFERRER        s            256a
      D REFER_URL       s            256a
      D S_Addr          s            256a
       *=====================================================================******
       * PROLOG
       * -Receive input from the remote browser
       * -Parse it into the external data structure
       *=====================================================================******
       /copy CGIDEV2/qrpglesrc,prolog1
       *=====================================================================******
       * Mainline
       *=====================================================================******
       * Load skeleton output html
      C                   exsr      LoadHtml
       *---------------------------------------------------------------------
       * Retrieve all environment variables
      C                   exsr      rtvenvvar
       * Substitute environment variables values into html variables
      C                   exsr      setvardata
       * Write out html
      C                   callp     wrtsection('all')
       * Do not delete the call to wrtsection with section name *fini.  It is needed
       * to ensure that all output html that has been buffered gets output.
      C                   callp     wrtsection('*fini')
      C                   eval      *inlr = *on
      C                   return
       *---------------------------------------------------------------------
       * Retrieve all environment variables
       *---------------------------------------------------------------------
      C     rtvenvvar     begsr
       * Query string
      C                   eval      Q_String=getenv('QUERY_STRING':
      C                             qusec)
       * Server's software
      C                   eval      S_Software=getenv('SERVER_SOFTWARE':
      C                             qusec)
       * Server's Address
      C                   eval      S_Addr=getenv('SERVER_ADDR':
      C                             qusec)
       * Server's Name
      C                   eval      S_Name=getenv('SERVER_NAME':
      C                             qusec)
       * Server's Protocol
      C                   eval      S_Protocol=getenv('SERVER_PROTOCOL':
      C                             qusec)
       * Gateway Interface
      C                   eval      G_Interf=getenv('GATEWAY_INTERFACE':
      C                             qusec)
       * HTTP Accept
      C                   eval      HTTP_Acc=getenv('HTTP_ACCEPT':
      C                             qusec)
       * HTTP Cookie
      C                   eval      HTTP_Coo=getenv('HTTP_COOKIE':
      C                             qusec)
       * HTTP_HOST
      C                   eval      HTTP_HOST=getenv('HTTP_HOST':
      C                             qusec)
       * HTTP User Agent
      C                   eval      HTTP_UserA=getenv('HTTP_USER_AGENT':
      C                             qusec)
       * Server's Port
      C                   eval      S_Port=getenv('SERVER_PORT':
      C                             qusec)
       * Request Method
      C                   eval      R_Method=getenv('REQUEST_METHOD':
      C                             qusec)
       * Path Info
      C                   eval      P_Info=getenv('PATH_INFO':
      C                             qusec)
       * Path Translated
      C                   eval      P_Trans=getenv('PATH_TRANSLATED':
      C                             qusec)
       * Script Name
      C                   eval      Script_N=getenv('SCRIPT_NAME':
      C                             qusec)
       * Remote Host
      C                   eval      R_Host=getenv('REMOTE_HOST':
      C                             qusec)
       * Remote Address
      C                   eval      R_Addr=getenv('REMOTE_ADDR':
      C                             qusec)
       * Content Type
      C                   eval      C_Type=getenv('CONTENT_TYPE':
      C                             qusec)
       * Content Length
      C                   eval      C_Length=getenv('CONTENT_LENGTH':
      C                             qusec)
       * IBM CCSID Value
      C                   eval      IBM_CCSID=getenv('IBM_CCSID_VALUE':
      C                             qusec)
       * AUTH_TYPE
      C                   eval      AUTH_TYPE=getenv('AUTH_TYPE':
      C                             qusec)
       * User ID of the remote user
      C                   eval      REMOTE_IDE=getenv('REMOTE_IDENT':
      C                             qusec)
       * User name passed for identification
      C                   eval      REMOTE_USE=getenv('REMOTE_USER':
      C                             qusec)
       * CGI_ASCII_CCSID
      C                   eval      CGI_A_CCS=getenv('CGI_ASCII_CCSID':
      C                             qusec)
       * CGI_MODE
      C                   eval      CGI_MODE=getenv('CGI_MODE':
      C                             qusec)
       * CGI_EBCDIC_CCSID
      C                   eval      CGI_E_CCS=getenv('CGI_EBCDIC_CCSID':
      C                             qusec)
       * HTTP Referer (page calling this one)
      C                   eval      HTTP_Refer=getenv('HTTP_REFERER':
      C                             qusec)
      C                   eval      REFERRER=getenv('REFERRER':
      C                             qusec)
      C                   eval      REFER_URL=getenv('REFERRER_URL':
      C                             qusec)
       *
      C                   endsr
       *---------------------------------------------------------------------
       * Set variable data for skeleton output html
       *---------------------------------------------------------------------
      C     setvardata    begsr
       * Query String
      C                   callp     updHTMLvar('Q_STRING':Q_String:
      C                             InitHTMLVars)
       * Server Software
      C     S_Software    ifeq      *blanks
      C                   eval      S_Software = NotAvail
      C                   endif
      C                   callp     updHTMLvar('S_SOFTWARE':S_Software)
       * Server Addr
      C     S_Addr        ifeq      *blanks
      C                   eval      S_Addr     = NotAvail
      C                   endif
      C                   callp     updHTMLvar('S_ADDR':S_Addr)
       * Server Name
      C     S_Name        ifeq      *blanks
      C                   eval      S_Name     = NotAvail
      C                   endif
      C                   callp     updHTMLvar('S_NAME':S_Name)
       * Server Protocol
      C     S_Protocol    ifeq      *blanks
      C                   eval      S_Protocol = NotAvail
      C                   endif
      C                   callp     updHTMLvar('S_PROTOCOL':S_Protocol)
       * Gateway Interface
      C     G_Interf      ifeq      *blanks
      C                   eval      G_Interf   = NotAvail
      C                   endif
      C                   callp     updHTMLvar('G_INTERF':G_Interf)
       * HTTP Accept
      C     HTTP_Acc      ifeq      *blanks
      C                   eval      HTTP_Acc   = NotAvail
      C                   endif
      C                   callp     updHTMLvar('HTTP_ACC':HTTP_Acc)
       * HTTP Cookie
      C     HTTP_Coo      ifeq      *blanks
      C                   eval      HTTP_Coo   = NotAvail
      C                   endif
      C                   callp     updHTMLvar('HTTP_COO':HTTP_Coo)
       * HTTP Host
      C     HTTP_HOST     ifeq      *blanks
      C                   eval      HTTP_HOST  = NotAvail
      C                   endif
      C                   callp     updHTMLvar('HTTP_HOST':HTTP_HOST)
       * HTTP User Agent
      C     HTTP_UserA    ifeq      *blanks
      C                   eval      HTTP_UserA = NotAvail
      C                   endif
      C                   callp     updHTMLvar('HTTP_USERA':HTTP_UserA)
       * Server Port
      C     S_Port        ifeq      *blanks
      C                   eval      S_Port     = NotAvail
      C                   endif
      C                   callp     updHTMLvar('S_PORT':S_Port)
       * Request Method
      C     R_Method      ifeq      *blanks
      C                   eval      R_Method   = NotAvail
      C                   endif
      C                   callp     updHTMLvar('R_METHOD':R_Method)
       * Path Info
      C     P_Info        ifeq      *blanks
      C                   eval      P_Info     = NotAvail
      C                   endif
      C                   callp     updHTMLvar('P_INFO':P_Info)
       * Path Translated
      C     P_Trans       ifeq      *blanks
      C                   eval      P_Trans    = NotAvail
      C                   endif
      C                   callp     updHTMLvar('P_TRANS':P_Trans)
       * Script Name
      C     Script_N      ifeq      *blanks
      C                   eval      Script_N   = NotAvail
      C                   endif
      C                   callp     updHTMLvar('SCRIPT_N':Script_N)
       * Remote Host
      C     R_Host        ifeq      *blanks
      C                   eval      R_Host     = NotAvail
      C                   endif
      C                   callp     updHTMLvar('R_HOST':R_Host)
       * Remote Address
      C     R_Addr        ifeq      *blanks
      C                   eval      R_Addr     = NotAvail
      C                   endif
      C                   callp     updHTMLvar('R_ADDR':R_Addr)
       * Content Type
      C     C_Type        ifeq      *blanks
      C                   eval      C_Type     = NotAvail
      C                   endif
      C                   callp     updHTMLvar('C_TYPE':C_Type)
       * Content Length
      C     C_Length      ifeq      *blanks
      C                   eval      C_Length   = NotAvail
      C                   endif
      C                   callp     updHTMLvar('C_LENGTH':C_Length)
       * IBM CCSID Value
      C     IBM_CCSID     ifeq      *blanks
      C                   eval      IBM_CCSID  = NotAvail
      C                   endif
      C                   callp     updHTMLvar('IBM_CCSID':IBM_CCSID)
       * AUTH_TYPE
      C     AUTH_TYPE     ifeq      *blanks
      C                   eval      AUTH_TYPE  = NotAvail
      C                   endif
      C                   callp     updHTMLvar('AUTH_TYPE':AUTH_TYPE)
       * User ID of the remote user
      C     REMOTE_IDE    ifeq      *blanks
      C                   eval      REMOTE_IDE = NotAvail
      C                   endif
      C                   callp     updHTMLvar('REMOTE_IDE':REMOTE_IDE)
       * User name passed for identification
      C     REMOTE_USE    ifeq      *blanks
      C                   eval      REMOTE_USE = NotAvail
      C                   endif
      C                   callp     updHTMLvar('REMOTE_USE':REMOTE_USE)
       * CGI_ASCII_CCSID
      C     CGI_A_CCS     ifeq      *blanks
      C                   eval      CGI_A_CCS  = NotAvail
      C                   endif
      C                   callp     updHTMLvar('CGI_A_CCS':CGI_A_CCS)
       * CGI_MODE
      C     CGI_MODE      ifeq      *blanks
      C                   eval      CGI_MODE   = NotAvail
      C                   endif
      C                   callp     updHTMLvar('CGI_MODE':CGI_MODE)
       * CGI_EBCDIC_CCSID
      C     CGI_E_CCS     ifeq      *blanks
      C                   eval      CGI_E_CCS  = NotAvail
      C                   endif
      C                   callp     updHTMLvar('CGI_E_CCS':CGI_E_CCS)
       * HTTP referer
      C     HTTP_Refer    ifeq      *blanks
      C                   eval      HTTP_Refer = NotAvail
      C                   endif
      C                   callp     updHTMLvar('HTTP_REFER':HTTP_Refer)
       * Meaning of «I»Not available«/I»
      C                   callp     updHTMLvar('NOTAVAIL':NotAvail)
      C                   endsr
       *---------------------------------------------------------------------
       * Load skeleton output html
       *---------------------------------------------------------------------
      C     LoadHtml      begsr
      C                   eval      lng = uppify(lng)
      C                   callp     gethtml('DEMOHTML' + %trimr(lng):
      C                             'CGIDEV2':
      C                             'ENVVAR':
      C                             '«as400»')
      C                   endsr
0.041 sec.s