Web Server Variables and CGI environment variables
accessing CGI environment- and Internet server variables from within a eDeveloper program
In order to pass data in a request from a CGI script, a web server uses the command line and envronment variables (according to the CGI specification). These variables then contain important information about the request and the client and you can access this information from within CGI scripts. In Magic & Internet applications which receive requests, you might want to access and use this information as well.
Examples for such information are f.i. the IP address of the client (REMOTE_ADDR) and the host name of the client (REMOTE_HOST).
If you protected your Magic & internet application with SSL and client certificates, you might want to get some information about the client and server certificate and decide if you accept or reject that request.
Similarly, Cookies are exchanged between http client (browser) and server (web server) by means of http header variables. Cookies will have been however already been disjointed by the requester for you. While the CGI environment variable 'HTTP_COOKIE' contains the complete cookie string, you can access the cookies by
GetParam() with the name of a cookie as parameter. This works without having to define the name of the cookie as token in the HttpVars (find more information about HttpVars below).
Besides information about the client and the request, CGI also suggests that some information should be exposed as environment variables to CGI scripts which are not request specific. This is e.g. information about the installed server software, the protocol, ... Information you might want to use within your Magic & internet application as well (f.i. to find out what server is used).
The Magic requester(s) exposes this information to the Magic application which receives the request as global parameters (global variables). Inside your Magic Internet application you can access the CGI environment- and Server variables then with the function GetParam(). The IP address of the client you e.g. would get with GetParam('REMOTE_ADDR').
Since you cannot distinguish within your Magic application if a particular internet program was invoked by the Magic CGI requester, the ISAPI requester or the Apache loadable module requester, the mechanism for accessing CGI environment and server variables is the same. You use GetParam() to access the information. There are however differences in which information these different gateways provide to your application. Within a program invoked by the ISAPI requester you e.g. are able to retrieve more information than if the same program had been invoked by the CGI requester. Besides the environment variables defined in the CGI specification, the ISAPI requester will also expose some server variables which are specific to IIS.
Preparing your Magic & Internet application to receive environemnet and server variables HttpVars
There's two environment variables with information about the remote request which you can always query with
GetParam(): REMOTE_ADDR and REMOTE_HOST. To be able to receive any other environment variable, you need to modify the HttpVars entry in the requester .ini (mgreq.ini) first. HttpVars needs to contain a comma seperated list with names of those variables which you want the requester to expose to your Magic application. If you do not put the name of a environment variable in this list, you cannot query its value.
If you want f.i. to be able to query the values of variables HTTP_REFERER, QUERY_STRING, HTTP_COOKIE within your Magic program, you need to put following information in the [REQUESTER_ENV] section of your mgreq.ini:
HttpVars=HTTP_REFERER,QUERY_STRING,HTTP_COOKIE
Do not intersperse blanks in the string following the "
HttpVars=". Your requester may not be able to read this.
Note: The length of the string following the HttpVars definition in the .ini is NOT unlimited. Magic resricts either the maximum length of this string or the number of variables (tokens). There's no documentation. If you do however put a HttpVars definition in your mgreq.ini which is either too long or contains too many tokens (variable names), the requester will cease working. You'll get an errror (-103): "Application not supported by any Enterprise server". This is misleading of course and you should avoid this situation. During some test with 9.4 SP7 following HttpVars definition worked:
HttpVars=ALL_HTTP,ALL_RAW,CERT_COOKIE,CERT_FLAGS,CERT_ISSUER,CERT_KEYSIZE,CERT_SECRETKEYSIZE,CERT_SERIALNUMBER,CERT_SERVER_ISSUER,CERT_SERVER_SUBJECT,CERT_SUBJECT,CONTENT_TYPE,HTTPS,HTTPS_KEYSIZE,HTTPS_SECRETKEYSIZE,HTTPS_SERVER_ISSUER,HTTPS_SERVER_SUBJECT,HTTP_ACCEPT,HTTP_ACCEPT_ENCODING,HTTP_ACCEPT_LANGUAGE,HTTP_CONNECTION,HTTP_COOKIE,HTTP_HOST,HTTP_REFERER,HTTP_USER_AGENT,HTTP_VERSION,INSTANCE_ID,INSTANCE_META_PATH,LOCAL_ADDR,LOGON_USER,PATH_INFO,PATH_TRANSLATED,QUERY_STRING,REMOTE_PORT
While following definition resulted in an error# -103:
HttpVars=ALL_HTTP,ALL_RAW,CERT_COOKIE,CERT_FLAGS,CERT_ISSUER,CERT_KEYSIZE,CERT_SECRETKEYSIZE,CERT_SERIALNUMBER,CERT_SERVER_ISSUER,CERT_SERVER_SUBJECT,CERT_SUBJECT,CONTENT_TYPE,HTTPS,HTTPS_KEYSIZE,HTTPS_SECRETKEYSIZE,HTTPS_SERVER_ISSUER,HTTPS_SERVER_SUBJECT,HTTP_ACCEPT,HTTP_ACCEPT_ENCODING,HTTP_ACCEPT_LANGUAGE,HTTP_CONNECTION,HTTP_COOKIE,HTTP_HOST,HTTP_REFERER,HTTP_USER_AGENT,HTTP_VERSION,INSTANCE_ID,INSTANCE_META_PATH,LOCAL_ADDR,LOGON_USER,PATH_INFO,PATH_TRANSLATED,QUERY_STRING,REMOTE_PORT,REMOTE_HOST
The second HttpVars definition contains one more token (REMOTE_HOST) and is few characters longer
- It seems that the internet requester(s) saw quite a few changes in v9.4 SP8 (http://ftp.magicsoftware.com/ver/docs/Downloads/v9product/v94_sp8_ReleaseNotes.pdf∞ ).
- The problem described above (errror (-103): "Application not supported by any Enterprise server") does not occur anymore. The behaviour changed with v9.4 SP8:
- REMOTE_ADDR and REMOTE_HOST are no longer filled by default. If you want to query this variables you have to put it into your mgreq.ini HttpVars= string like in
- "HttpVars = REMOTE_ADDR,REMOTE_HOST" (without the quotes). Note that the blanks on the left and right of the "=" sign are mandatory now; if you specify (as in previous versions) HttpVars=REMOTE_ADDR,REMOTE_HOST you'll experience problems.
-
- The length restriction for the HttpVars string seems to be still in place. If the string gets too long, the requesters do not provide you with the values in the Magic environment.
- Different from before 9.4 SP8 is that the broker error (-103) does not occur anymore. If thats however better than not providing the application with the required values ... is a question.
Examples and list of possible CGI environment / Sever-variables
Below you find output of a sample program which echoes CGI environment and Internet Server variables from within a Magic application to html. The Magic program itself I made part of the
Form-based File Upload in HTML sample which is available for download. Sample output is generated with IIS6.0 on Windows XP SP2. Other webservers may have a bit different set of variables. The Magic version I tested with was 9.4 SP8. The required
HttpVars= definition in mgreq.ini was as given in the sample above. You'll note that some of the values for variables are NOT filled when you run the sample program with the CGI requester, while they ARE filled when you run the same program with the ISAPI requester. This is a limitation of the Magic 9.4 CGI requester.
Output of a CGI / server variable "echo" program written in Magic and invoked with 9.4 ISAPI requester and CGI requster:
| Variable |
return value ISAPI requester (mgrqispi94.dll) |
return value CGI requester (mgrqcgi94.exe) |
| ALL_HTTP |
HTTP_ACCEPT:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-quickviewplus, */* HTTP_ACCEPT_LANGUAGE:en-us,de;q=0.5
HTTP_CONNECTION:Keep-Alive HTTP_HOST:andreas HTTP_REFERER:https://andreas/Magic94Scripts/MGrqispi94.dll?AppName=FileUpload&PrgName=ICA200_01&ARGUMENTS=-AgBCnMKMkb4nc-yObt2df4jLJ9S7UDDWq5zIf2kVIy0x1gbihbH879A== HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1) HTTP_COOKIE:CVLANG=GB; sess_id="gBCnMKMkb4nc-yObt2df4jLJ9S7UDDWq5zIf2kVIy0x1gbihbH879A==" HTTP_UA_CPU:x86 HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_X_REWRITE_URL:/Magic94Scripts/MGrqispi94.dll?AppName=FileUpload&PrgName=ICA500_10&ARGUMENTS=-AA |
|
| ALL_RAW |
Accept: image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-quickviewplus, */* Accept-Language: en-us,de;q=0.5 Connection: Keep-Alive
Host: andreas Referer: https://andreas/Magic94Scripts/MGrqispi94.dll?AppName=FileUpload&PrgName=ICA200_01&ARGUMENTS=-AgBCnMKMkb4nc-yObt2df4jLJ9S7UDDWq5zIf2kVIy0x1gbihbH879A==
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)
Cookie: CVLANG=GB; sess_id="gBCnMKMkb4nc-yObt2df4jLJ9S7UDDWq5zIf2kVIy0x1gbihbH879A=="
UA-CPU: x86
Accept-Encoding: gzip, deflate
X-Rewrite-URL: /Magic94Scripts/MGrqispi94.dll?AppName=FileUpload&PrgName=ICA500_10&ARGUMENTS=-AA |
|
| APPL_MD_PATH |
|
|
| APPL_PHYSICAL_PATH |
|
|
| APP_POOL_ID |
|
|
| AUTH_PASSWORD |
|
|
| AUTH_TYPE |
|
|
| AUTH_USER |
|
|
| CACHE_URL |
|
|
| CERT_COOKIE |
455a84e84b12be870d80109937f91d63 |
455a84e84b12be870d80109937f91d63 |
| CERT_FLAGS |
1 |
1 |
| CERT_ISSUER |
C=ZA, O=Thawte Consulting (Pty) Ltd., CN=Thawte Personal Freemail Issuing CA |
C=ZA, O=Thawte Consulting (Pty) Ltd., CN=Thawte Personal Freemail Issuing CA |
| CERT_KEYSIZE |
128 |
|
| CERT_SECRETKEYSIZE |
4096 |
|
| CERT_SERIALNUMBER |
7c-2c-76-fc-01-14-6f-3e-56-65-a2-c8-a5-35-90-ec |
7c-2c-76-fc-01-14-6f-3e-56-65-a2-c8-a5-35-90-ec |
| CERT_SERVER_ISSUER |
C=DE, S=BAVARIA, L=MUNICH, O=ANDREAS
SEDLMEIER CONSULTING, OU=IT, CN=ANDREAS' TEST CA, E=sedlmeier@hotmail.com |
|
| CERT_SERVER_SUBJECT |
C=DE, S=BAVARIA, L=MUNICH, O=Andreas
Sedlmeier Consulting Services, OU=IT, CN=andreas |
|
| CERT_SUBJECT |
CN=Thawte Freemail Member, E=sedlmeier@hotmail.com |
|
| CONTENT_LENGTH |
|
|
| CONTENT_TYPE |
|
|
| GATEWAY_INTERFACE |
|
|
| HTTPS |
on |
on |
| HTTPS_KEYSIZE |
128 |
128 |
| HTTPS_SECRETKEYSIZE |
4096 |
4096 |
| HTTPS_SERVER_ISSUER |
C=DE, S=BAVARIA, L=MUNICH, O=ANDREAS
SEDLMEIER CONSULTING, OU=IT, CN=ANDREAS' TEST CA, E=sedlmeier@hotmail.com |
|
| HTTPS_SERVER_SUBJECT |
C=DE, S=BAVARIA, L=MUNICH, O=Andreas
Sedlmeier Consulting Services, OU=IT, CN=andreas |
|
| HTTP_ACCEPT |
image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword,
application/x-quickviewplus, */* |
image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash,
application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-quickviewplus,
*/* |
| HTTP_ACCEPT_ENCODING |
gzip, deflate |
gzip, deflate |
| HTTP_ACCEPT_LANGUAGE |
en-us,de;q=0.5 |
en-us,de;q=0.5 |
| HTTP_CONNECTION |
Keep-Alive |
|
| HTTP_COOKIE |
CVLANG=GB; sess_id="gBCnMKMkb4nc-yObt2df4jLJ9S7UDDWq5zIf2kVIy0x1gbihbH879A==" |
|
| HTTP_HOST |
andreas |
andreas |
| HTTP_REFERER |
https://andreas/Magic94Scripts/MGrqispi94.dll?AppName=FileUpload&PrgName=ICA200_01&ARGUMENTS=-AgBCnMKMkb4nc-yObt2df4jLJ9S7UDDWq5zIf2kVIy0x1gbihbH879A== |
|
| HTTP_USER_AGENT |
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727;InfoPath.1) |
|
| HTTP_VERSION |
HTTP/1.1 |
|
| INSTANCE_ID |
1 |
1 |
| INSTANCE_META_PATH |
/LM/W3SVC/1 |
|
| LOCAL_ADDR |
172.23.107.107 |
|
| LOGON_USER |
|
|
| PATH_INFO |
|
|
| PATH_TRANSLATED |
C:\web.dev\www\htdocs |
C:\web.dev\www\htdocs |
| QUERY_STRING |
AppName=FileUpload&PrgName=ICA500_10&ARGUMENTS=-AA |
AppName=FileUpload&PrgName=ICA500_10&ARGUMENTS=-AA |
| REMOTE_ADDR |
172.23.107.107 |
|
| REMOTE_HOST |
172.23.107.107 |
|
| REMOTE_PORT |
1380 |
|
| REMOTE_USER |
|
|
| REQUEST_METHOD |
|
|
| SCRIPT_NAME |
|
|
| SCRIPT_TRANSLATED |
|
|
| SERVER_NAME |
|
|
| SERVER_PORT |
|
|
| SERVER_PORT_SECURE |
|
|
| SERVER_PROTOCOL |
|
|
| SERVER_SOFTWARE |
|
|
| SSI_EXEC_DISABLED |
|
|
| UNENCODED_URL |
|
|
| UNMAPPED_REMOTE_USER |
|
|
| URL |
|
|
See also
-
The Common Gateway Interface∞
-
RFC 1867 - Form-based File Upload in HTML - with eDeveloper (which contains the sample program to generate above sample output)
Back to:
TuTorials
CategoryWeb
There are no comments on this page. [Add comment]