What are Environment Variables? |
Topics | |
The environment variables are available to aptilis in a key-based array called _ENV[ ]. If do not understand the notion of key based arrays, just have a look at the examples below, and in particular how to retrieve a single value. You don't need much more theory to retrieve key based array elements such as the variables passed to your scripts by the webserver.
notes: I saved the example scripts in a directory called:
c:\aptilis and I called them with
the URLs
http://192.1.1.16/cgi-bin/aptilis.exe?file=c:\aptilis\env1.e.txt
and
http://192.1.1.16/cgi-bin/aptilis.exe?file=c:\aptilis\env2.e.txt
respectively.
Example 1: Retrieving one value (script: env1.e.txt)
sub main
print("Content-type: text/plain\n\n")
print(_ENV["HTTP_HOST"]$, "\n")
end main
Result:
192.1.1.16 |
Example 2: Retrieving all available values (script: env2.e.txt)
sub main
print("Content-type: text/plain\n\n")
n = getArraySize(_ENV[])
for i=1 to n
k = getNextKey(_ENV[]) $
print(k$, "=", _ENV[k$]$, "\n")
end for
end main
Result:
CGI_STDERR=cgierr.log QUERY_STRING=file=c:\aptilis\env2.e.txt REMOTE_ADDR=192.1.1.16 REMOTE_HOST=192.1.1.16 REMOTE_USER=- CONTENT_LENGTH=0 CONTENT_TYPE= SCRIPT_NAME=/cgi-bin/aptilis.exe SCRIPT_PATH=cgi-bin REQUEST_METHOD=GET GATEWAY_INTERFACE=CGI/1.1 SERVER_PROTOCOL=HTTP/1.0 SERVER_PORT=80 SERVER_SOFTWARE=Xitami HTTP_CONTENT_LENGTH=0 HTTP_CONNECTION=Keep-Alive HTTP_USER_AGENT=Mozilla/4.06 [en] (WinNT; I ;Nav) HTTP_ACCEPT=image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */* HTTP_ACCEPT_ENCODING=gzip HTTP_ACCEPT_LANGUAGE=en HTTP_ACCEPT_CHARSET=iso-8859-1,*,utf-8 |
