Learn from sources
       Member GETPOST in CGIDEV2 / QRPGLESRC

       *=====================================================================
       *  RPG ILE PROGRAM CGIDEV2/GETPOST
       *
       *  CRTBNDRPG PGM(CGIDEV2/GETPOST) SRCFILE(CGIDEV2/QRPGLESRC)
       *         ACTGRP(GETPOST) DBGVIEW(*SOURCE)
       *
       *=====================================================================
       /copy CGIDEV2/qrpglesrc,hspecs
       /copy CGIDEV2/qrpglesrc,hspecsbnd
       /copy CGIDEV2/qrpglesrc,prototypeb
       /copy CGIDEV2/qrpglesrc,usec
       /copy CGIDEV2/qrpglesrc,variables3
       *
      D CrtLink         pr
       *
      D extHtml         s           2000    inz('/cgidev/html/getpost.txt')
       * Indicators for GetHtmlIfsMult subprocedure
      D IfsMultIndicators...
      d                 ds
      D  NoErrors                       n
      D  NameTooLong                    n
      D  NotAccessible                  n
      D  NoFilesUsable                  n
      D  DupSections                    n
      D  FileIsEmpty                    n
       *
      D xInput          s            100
      D myLink          s            500
       /free
 
            // Get browser input
            nbrVars=zhbgetinput(savedquerystring:qusec);
            xInput=zhbGetVar('xInput');
 
            // Load external HTML script
            IfsMultIndicators = getHtmlIfsMult(%trim(exthtml):'«as400»');
 
            // Create a link in variable "myLink"
            CrtLink();
 
            // Write HTML to output buffer
            updHtmlVar('prvInput':xInput);
            updhtmlvar('link':mylink);
            wrtSection('top');
 
            // Send the output buffer
            wrtsection('*fini');
 
            // Back to caller
            return;
 
       /end-free
       *=========================================================================
       * Create a link in variable "myLink"
       *=========================================================================
      p CrtLink         b
      D CrtLink         pi
      D unescaped       s          32767    varying
      D escaped         s          32767    varying
      D http_host       s             50
      D server_port     s              5
      D script_name     s             50
      D URL             s            500
       /free
 
            myLink=' ';
            if xInput=' ';
               return;
            endif;
 
            // "escape()" the input string
            unescaped=xInput;
            escaped=urlEscSeq(unescaped);
 
            URL='http://' + %trim(http_host);
            // Get some environment variables
            http_host=getenv('HTTP_HOST':qusec);
            server_port=getenv('SERVER_PORT':qusec);
            script_name=getenv('SCRIPT_NAME':qusec);
 
            // Create the URL
            URL='http://' + %trim(http_host);
            if server_port«»'80';
               URL=%trim(URL)+':'+%trim(server_port);
            endif;
            URL=%trim(URL)+%trim(script_name)+
                 '?xInput='+%trim(escaped);
 
            // Create the "myLink" variable
            mylink='«a href="' + %trim(URL) + '"»' +
                   %trim(URL) + '«/a»';
 
       /end-free
      p CrtLink         e
0.124 sec.s